tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Stone <>
Subject Re: RequestDispatcher and [contentType] question...
Date Fri, 16 Apr 2004 17:11:06 GMT
Yansheng Lin wrote:

> Hi, 
> You are confused with request and response.  The request is shared by the
> forwarding jsp and the forwarded jsp, not the response(well kind of, but not
> until it's being generated).  You will have to explicitly set the response
> contentType to utf-8 in the forwarded page.  
> -Yan

I see what you mean.

How I put it together in my mind--naively I can't say--is that the 
servlet begins constructing a response buffer to the request and the 
contentType gets set by res.setContentType(). Shortly following this, 
the request and response are forwarded for additional processing by a 
JSP page. Upon which the response buffer is cleared as it has not been 
committed. Since no attribute to the page directive is provided in the 
JSP, the default behavior is to set the contentType to 
"text/html;charset=ISO-8859-1". The response returns to the controlling 
servlet and gets committed to the client, having overwritten the 
original call to setContentType.

Lesson learned: if one forwards control to a JSP page, the page 
directive must set contentType and/or pageEncoding, either electively or 
by requirement, otherwise the JSP defaults will supersede any work done 
prior to the forwarding of the request.

Thank you, Yansheng.


> -----Original Message-----
> From: Timothy Stone [] 
> Sent: April 15, 2004 14:45
> To: Tomcat Users List
> Cc:
> Subject: Re: RequestDispatcher and pageEncoding question...
> Timothy Stone wrote:
>>Timothy Stone wrote:
>>>A servlet I am debugging and trying to understand sets the response's 
>>>contentType as follows:
>>>response.setContentType( "text/html;charset=UTF-8" );
>>>Shortly following the following forward is done:
>>>request.getRequestDispatcher( jspPage ).forward( request, response );
>>>The JSP forwarded gets the response with the contentType set, but 
>>>commiting the response seems to reset the contentType to 
>>>text/html;charset=ISO-8859-1, the default.
>>>The JSP in the forward does not set a pageEncoding attribute in the 
>>>page directive, so I'm pointing the finger there at the moment. Can 
>>>someone outline what is going on behind the scenes of the 
>>>requestDispatcher call that would be reseting the response's contentType?
>> From the documentation:
>>"...Uncommitted output in the response buffer is automatically cleared 
>>before the forward."
>>So, is the call to response.setContentType() being "reset" on the 
>>forward()? Can anyone elaborate?
> I see that nearly exactly what I'm experiencing was discussed last year 
> regarding the behavior as seen through Struts. No resolution given.
> I'll continue to watch this new thread for suggestions.
> Again, with many thanks,
> Tim

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message