tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Junghans" <Andreas.Jungh...@fh-karlsruhe.de>
Subject Re: HttpServletResponseWrapper error.
Date Tue, 22 Jan 2002 09:08:33 GMT
Hi Jay,

> This works with Resin. However, in Tomcat, when I wrap the response, I
> "commit" the original response object and can not forward to a thank you
> page. I catch a "java.lang.IllegalStateException: Cannot forward after
> response has been committed". In my debug tests, the response is committed
> during the RequestDispatchers forward method.

I've had a similar case. The problem is that Tomcat calls flushBuffer() on
the response, which seems to be completely "legal" regarding the Servlet
spec. Calling flushBuffer() commits the response, and after that, no forward
is possible.

If Resin behaves differently, this is probably due to a different buffer
size or different buffer handling. Perhaps Resin doesn't call flushBuffer()
at all, which (in my understanding) is just as spec compliant as Tomcat's
behaviour.

What you have to do is override flushBuffer() in your response wrapper to
prevent HttpServletResponseWrapper from passing the flush to the original
response. In my case, I simply added an empty flushBuffer() method to the
wrapper, and it worked. However, you should note that some containers
_might_ rely on the side effects of the original flushBuffer() (e.g. that
exceptions are raised when calling methods like sendRedirect() afterwards).
Although this is highly unlikely, you have to "simulate" these effects in
your wrapper if you want to be _absolutely_ sure your application runs in
every container.

Regards

  Andreas Junghans



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