Jean-Michel Leon wrote:

> >
> > > I'm not sure if this is compliant with the spec
> >
> > So check out the JSP spec.
>
> I did. It's just that the spec (JSP 1.0, p43, 2.7.1) doesn't say that
> this is the only way people should use to set the mime type. Since in
> our case, the mime type is not static for this page (it's computed based
> on the user agent we're talking to), I believe (correct me if I'm wrong)
> I can't do that with the page directive.
>

You are right, you cannot set a dynamic content type with the page directive.  But
I believe calling Tomcat's behavior with respect to setting the content type a
"bug" is really presumptuous.

The behavior is deliberate in the Tomcat code -- it sets the "Content-Type" header
itself based on whatever you specify as an argument to setContentType() --
defaulting to "text/html" if you have not called this method.  The fact that
you've set a header yourself with the same header type creates a second one, which
the browser (quite correctly) ignores.

You also need to recognize that the JSP spec is not the only one that matters
(although you also mention that you haven't even read the JSP spec that Tomcat is
based on :-).  If you go to the servlet spec, and the associated API docs, you see
that setContentType() and setContentLength(), and so on, are provided as
mechanisms to set the corresponding HTTP headers.

Should the API docs mention that you should *not* try to use setHeader to set the
content type?  Perhaps, but you need to remember one more thing -- when the specs
are not clear, Tomcat is the "reference implementation" for the servlet and JSP
specifications, so in cases where the spec is ambiguous or not clear, Tomcat's
behavior should be considered correct.  The fact that it is open source now makes
it obvious to everyone what the actual behavior is.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to