DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5715>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5715

response.setContentType() in Filter.doFilter not changed content type





------- Additional Comments From [EMAIL PROTECTED]  2002-11-04 14:15 -------
A possible fix for this:

1)  If you are using a filter, wrap your response in a response wrapper that
does not allow the content-type to be set by the page.  The code for this is:

The following filter works:

/**
 * @author <a href="mailto:scott@;atlassian.com">Scott Farquhar</a>
 */
public class EncodingFilter implements Filter
{

    public void destroy()
    {
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse
servletResponse, FilterChain filterChain) throws IOException, ServletException
    {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("text/html;charset=UTF-8");

        filterChain.doFilter(servletRequest,
                new HttpServletResponseWrapper((HttpServletResponse)
servletResponse)
                {
                    public void setContentType(String s)
                    {
                        System.out.println("EncodingFilter.setContentType " + s);
                        new Throwable().printStackTrace();
                        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.

                            //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.

                            //And besides, this is the way that we do it in
JIRA, and I want to test this against different
                            //servers
                        }
                        else
                        {
                            super.setContentType(s);
                        }
                    }

                });
        System.out.println("servletResponse.getCharacterEncoding() = " +
servletResponse.getCharacterEncoding());
    }

    public void init(FilterConfig filterConfig) throws ServletException
    {
    }

}

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@;jakarta.apache.org>

Reply via email to