Anand Kumar Sankaran wrote:
>
>
>>
>> Note that you can forward to another JSP page, or to a servlet.
>> Also, a servlet can
>> forward to a JSP page by using the RequestDispatcher.forward()
>> mechanism.
>>
>
> If I am right, RequestDispatcher.forward() transfers the
> HttpServletRequest object and HttpServletResponse object too - one can
> use this like servlet chaining and continue with processing.
>
You are correct that both the request and the response objects are
transferred (this applies to RequestDispatcher.forward() and
<jsp:forward> (which uses RequestDispatcher.forward() in its generated
code). The idea is that the page or servlet you transfer to is
completely responsible for creating the current response.
Whether or not you can use this for "servlet chaining" depends on your
definition of the term. Historicallly, most people have used that term
to mean "call another servlet, examine the output it produces, and do
something with it." Request forwarding does not allow you to do this.
In fact, the page (or servlet) you transfer from does not participate in
creating the response any more -- in a JSP page, <jsp:forward>
effectively stops interpretation of the page, while in a servlet, the
only valid thing for you to do is clean up and return from your
doGet()/doPost() method.
In either case, you also need to make sure that you have not generated
output in the originating servlet or page, or that (if you have) you
haven't exceeded the buffer size that you declared. Otherwise, you will
get a runtime exception, because the HTTP headers of the response are
set when output is initially flushed to the response stream -- and the
page/servlet you forward to would not be able to modify them.
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