tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Farquhar <sc...@atlassian.com>
Subject Setting Content Type in Servlet Filter fails
Date Sat, 02 Nov 2002 18:08:20 GMT
Guys,

Currently, when a JSP is compiled to java code, it includes a line such as:

   response.setContentType("text/html;charset=ISO-8859-1");

However, this seems to preclude setting the content type in a servlet 
filter, as anything that is set in the filter is over-ridden by the JSP. 
  Eg, with our product JIRA - we must cater for many different character 
sets, and so we can't hard-code the characterset in the header of the 
JSP, and must set it at runtime.

To do so, we use a filter that does this:

   servletRequest.setCharacterEncoding("UTF-8");
   servletResponse.setContentType("text/html;charset=UTF-8");

Which works fine on Orion and Resin.  But fails on Tomcat and Jetty 
(presumably because they share the same JSP compilation engine).

You can't set it after the JSP has been called, because by then the 
response has been committed, and you can't set headers after that time.

There is already a bug raised in bugzilla for this:
   http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5715

Any ideas on how to fix it?  Could you make setContentType immutable? 
So only allow it to be set once?  Else change the JSP compiler so that 
it checks if contentType has already been set before setting it?

This prevents JIRA running on Tomcat with configurable charactersets, 
and presumably other applications are in the same position.

Thanks for your time.

Scott

-- 

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


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


Mime
View raw message