Fabrice Sarciaux wrote:

> can someone tell me or direct me to a url where the usage of "forward" is
> explained because i can't get it to work. i keep getting :
>
> java.lang.IllegalStateException: Cannot forward when getOutputStream()
> already called.
>
> mycode:
>
> <java>
>  String url="welcome.jsp";
>  ServletContext context=getServletContext();
>  RequestDispatcher rd=context.getRequestDispatcher(url);
>  HttpServletResponse hsr=Response.getServletResponse();
>
>  rd.forward((ServletRequest)Request,hsr);
> </java>
>
> thanks
> fabrice
>

If you plan to use a RequestDispatcher.forward() call, then the originating
code should not try to get the output stream or print writer from the
HttpServletResponse -- you are, in essence, delegating responsibility for
creating the entire output page to the JSP (or whatever) you are forwardijng
to.

In a pure servlet environment, that's easy -- just avoid calling
response.getOutputStream() or response.getWriter().  In a JSP page, you are
kind of stuck because the generated code has probably already grabbed the
output stream, on the (reasonable) assumption that this page itself is going to
be responsible for the output.  You can tell for sure by looking at the Java
source code your JSP compiler generates.

Try moving this Java code into a real servlet (i.e. the Model 2 approach in the
JSP 0.92 specification), and you will see that it works just fine, lasts a long
time ... :-)

If you really want to do this all within a single JSP page, look at
RequestDispatcher.include instead -- this acts like server-side includes, so
you can incorporate the output of another JSP page into this one with it.

Craig McClanahan

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to