tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ahab Abouzour <>
Subject HttpServletResponse.setContentLength() method in Tomcat 5.5.9
Date Thu, 15 Sep 2005 18:12:40 GMT

Hello all,

My servlet stopped working when I moved from
Tomcat4.0.6 to Tomcat5.5.9. After investigating the
problem, it turns out that if the
HttpServletResponse.setContentLength() method is
called, subsequent calls (e.g. setHeader(),
addHeader(),addCookie()..etc) into the
HttpServletResponse object are completely ignored (or
discarded  from underneath!). 

For example, if I do the following in my service
method: (httpResponse is defined HttpServletResponse)

httpResopnse.setStatus(204); // I tried 200 and got
the same problem, I guess status code doesn't play
part in this problem.
httpResponse.setHeader("header1","value1"); //works
httpResponse.setHeader("header2","value2"); //works
httpResponse.setContentLength(0); // nothing gets set 
on the response object after this point
httpResponse.setHeader("header3","value3"); //
Cookie("JSESSIONID","myCookie")); // ignored!

My proxy shows that header1 and header2 are set
correctly but header3 and my cookie are missing! It
seems that it expects setContentLength is the last
method to be set on the response object and any method
call after that on the resopnse object gets ignored
(or discarded)

I have attached a simple servlet that reproduces this

My question: is this an expected behaviour? I checked
the http specs and the servlet 2.4 specs but nothing
specified this behaviour. Can someone please explain
if this is the expected behaviour (and why?
specs..etc) or it's a bug?

Thanks in advance,

Yahoo! Mail - PC Magazine Editors' Choice 2005
View raw message