>>> Jon Rosenberger <[EMAIL PROTECTED]> 18-Jul-00 6:26:43 PM
>>>

>For example, what happens to the code after a forward?
>Is it executed?

Of course it is. RequestDispatcher.forward() is just an API call -
it's not a language construct - how could it stop the rest of the code
from executing.

Think of it as a normal method call: the executiopn branches to the
specified servlet and when that servlet completes control returns to
the point where it was called.

Therefore the rest of the calling servlet is executed.


>It turns out that it is, which leads to more questions:
> - Can you still write to the output stream?

What does the spec say on this? I think you'll find it says that you
can't if the servlet you forward to writes to the OS.


>In fact, the following code will print "test" to the output
>stream, so you CAN keep on writing.

>public class ForwardServlet extends HttpServlet {
>   protected void doGet(HttpServletRequest req,....
>                RequestDispatcher dispatcher =
>
getServletContext().getRequestDispatcher("/test/AnotherPage.jsp");
>                dispatcher.forward(req, resp);
>                resp.getOutputStream().print("test");
>    }
>}

If the jsp files is actually sending anything then the behaviour of
your servlet container here is illegal. It MUST NOT allow a write to
the OS after a write has already taken place.



Nic

___________________________________________________________________________
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