tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Filters and HttpServletResponse.close();
Date Thu, 07 Feb 2002 05:12:19 GMT

On Wed, 6 Feb 2002, Glen Nakamura wrote:

> Date: Wed, 6 Feb 2002 18:59:13 -1000
> From: Glen Nakamura <>
> Reply-To: Tomcat Developers List <>
> To:
> Subject: Filters and HttpServletResponse.close();
> Aloha,
> When does the HttpServletResponse object get closed if the servlet doGet()
> method doesn't call HttpServletResponse.close() explicitly?
> For example, suppose a servlet filter creates a HttpServletResponseWrapper
> to wrap the initial HttpServletResponse and passes on this new response
> object down the doFilter() chain.  The servlet doGet() method eventually
> gets called, but doesn't explicitly call close() of the wrapped
> response object.  After tomcat returns from the container's invoke() method,
> it calls finishResponse() which is supposed to flush and close the response
> object, but isn't this the original response object?  What about the
> wrapped response object created by the filter?  It appears it never gets
> closed and is not flushed properly.  I think this explains why I'm not
> getting any output from my filter when doGet() doesn't explicitly call
> HttpServletResponse.close().  Did I miss something?

As you noted, Tomcat calls finishResponse() after the servlet returns.
However, this is called only on the *original* response that Tomcat
provided to the servlet -- not to any wrappers that your application has

It is your application's responsibility to ensure that anything it has
buffered in a response wrapper is flushed to the "real" response prior to
your filter returning from its doFilter() method.

> - Glen Nakamura

Craig McClanahan

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

View raw message