Setting character encoding is a view-specific idea. Personally at Atlassian we use an encoding filter to set the encoding for all our pages. It is attached.

However, we still have problems with i18n in Resin & WL7 (most probably due to sitemesh and not the filter).

Cheers,
Scott



Taavi Tiirik wrote:
Hi,

There is this parameter webwork.i18n.encoding in default.properties
that is used for file upload and in include tag as well.

Would it make sense to use the very same parameter for specifying
encoding for views? Or is this such a container specific task that has
to be solved outside of webwork? Currently webwork does not
set character encoding. And it seems to be too late to set it in the
view. Well, what do you think? Anybody cares to share their best
practices regarding setting character encoding?

with best wishes,
Taavi



-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! Get cracking and register here for some mind boggling fun and the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork



--


ATLASSIAN - http://www.atlassian.com
Expert J2EE Software, Services and Support
-------------------------------------------------------
Need a simple, powerful way to track and manage issues?
Try JIRA - http://www.atlassian.com/software/jira
/*
 * Atlassian Source Code Template.
 * User: sfarquhar
 * Date: 1/08/2002
 * Time: 09:27:01
 * CVS Revision: $Revision: 1.2 $
 * Last CVS Commit: $Date: 2002/12/16 02:25:18 $
 * Author of last CVS Commit: $Author: mike $
 */
package com.atlassian.jira.web.filters;

import com.atlassian.jira.config.properties.ApplicationProperties;
import com.opensymphony.util.TextUtils;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * This filter sets the request and response encoding, as well as preventing page 
caching.
 */
public class EncodingFilter implements Filter
{

    public void destroy()
    {
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain filterChain) throws IOException, ServletException
    {
        servletRequest.setCharacterEncoding(getEncoding());
        servletResponse.setContentType(getContentType());

        // prevent caching of JSPs
        if (servletResponse instanceof HttpServletResponse)
        {
            HttpServletResponse httpServletResponse = (HttpServletResponse) 
servletResponse;
            HttpServletRequest req = (HttpServletRequest) servletRequest;

            String uri = TextUtils.noNull(req.getRequestURI());
            String path = TextUtils.noNull(req.getServletPath());

            if (uri.indexOf(".jsp") > 0 || uri.indexOf(".jspa") > 0)
            {
                httpServletResponse.setHeader("Cache-Control", "no-cache, no-store,  
must-revalidate"); // http 1.1
                httpServletResponse.setHeader("Pragma", "no-cache"); // http 1.0
                httpServletResponse.setDateHeader("Expires", 0); // prevent proxy 
caching
            }
        }

        filterChain.doFilter(servletRequest,
                new HttpServletResponseWrapper((HttpServletResponse) servletResponse)
                {
                    public void setContentType(String s)
                    {
                        if (s.length() > "text/html".length() && s.charAt(0) == 't' && 
s.startsWith("text/html"))
                        {
                            //do nothing.  This call could be trying to set the 
charset to another charset.
                            //This is the case with Tomcat & Jetty, whose JSP compiler 
sets the charset, whether it
                            //is specified in the JSP page or not.

                            //So - if someone else is trying to set the content type 
to HTML, then they may also want
                            //to override the charset.  So - we just don't allow them 
to override the content-type
                            //if they are just setting to text/html.  If they want to 
overried with 'gif' or 'pdf'
                            //then go straight ahead.  Who are we to question the app 
server.  I mean...really....

                            //NB - this can also be accomplished by setting the 
charset manually in the JSP page & the decorator,
                            //but this approach allows for run-time flexibility of 
choosing the charsets.
                        }
                        else
                        {
                            super.setContentType(s);
                        }
                    }

                });
    }

    public void init(FilterConfig filterConfig) throws ServletException
    {
    }

    private static String getEncoding()
    {
        return new ApplicationProperties().getEncoding();
    }

    private static String getContentType()
    {
        return new ApplicationProperties().getContentType();
    }
}

Reply via email to