tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: Content Type and RequestDispatcher
Date Mon, 19 Jun 2000 17:36:48 GMT
Nacho wrote:

> Hola, Alex:
>
> > So, my first (somewhat long winded) question is: Is it a bug or a
> > feature that the "response.setContentType()" is ignored when using
> > RequestDispatcher.forward()?
> >
>
> AFAIK is you have commited part of the response to the client you can
> not set any more headers.. this is direct for include because it by
> definition flush ( commit for the case ) the buffers, and in the case of
> forward , i dont know the spec on this but can be that you have commited
> unadvertly the buffer, set a big buffer size and set autoflush to false,
> and do a try
>

"Bug versus feature" depends a little on the circumstances:

* If you call response.setContentType() before calling rd.forward(), and
  you have *not* yet committed the response, you should be OK.  The
  data buffer will be cleared, but the headers will be kept.  There was a
  bug in Tomcat 3.1 in a similar situation (doing a sendRedirect() instead
  of forward()) that cause the headers to be cleared as well -- this was
  fixed about a week ago.

* If you call response.setContentType() before calling rd.forward(), and
  you have already committed the response, the spec says you should
  get an IllegalStateException.  Tomcat currently ignores this attempt
  to set a header after commit.

* Servlets and JSP pages you include with RequestDispatcher.include()
  or <jsp:include> are specifically disallowed from setting response headers.
  They need to be set in the calling servlet or page.

Craig McClanahan



Mime
View raw message