>>> Stuart Maclean <[EMAIL PROTECTED]> 15-Aug-00 6:43:08 PM
>>>

>I see from the JSP 1.1 and Servlet 2.2 specs that
>this practice is prohibited, and attempts to use it are
>ignored.  Thus Tomcat is adhering to the specs in this
>case.  My question is "why is header manipulation within
>included servlets/JSP forbidden.  Neither spec gives any
>insight to the reasons for this behaviour.

Umm...I'm sure if you searched the archives for this list, or looked
around on one of the many FAQs you would find the answer.

But here goes nothing:

1. servlet A writes the following:

 <html>
   <head>
   <title>My document</title>
   </head>
   <body>
     <h1>My servlet</h1>

2. and then servlet A calls include() to a servlet B which writes

   <p>it's very interesting</p>

3. and returns to servlet A which continues to write:

   </body>
  </html>

4. and finishes the response.


Now consider point 2. at which the included servlet is called.

You notice that some output has already been written to the browser.


Now, if you consider the HTTP specification the scales will fall from
your eyes.

The browser MUST recieve the HTTP header before the content. This is
so that the browser knows things like what content type the content is
and how many bytes it is. It is also so that the browser knows *where*
the header will be.

If the server must send the header before the content of the response
then it has to do one of 2 things:

1. ensure that the header is written before the content
2. buffer all the output until the output is finished

the designers of the API chose to do 1. because to rely on 2. would
be foolish.

Why would it be foolish? Consider a 400K HTML page. Would it be
sensible to buffer that everytime the page was asked for?

"Ah!" you say... "but the container could at least buffer the bit
before the included servlet is called". Yes... it could. But what if
that was the bit that was 398K long? And what happens when the
included servlet includes another servlet? which includes another
servlet? Which servlets are allowed to alter headers and which
aren't?


And that is why the included can't see headers.


Nic Ferrier
(with apoligies to Rudyard Kipling)

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to