JSP, forward, include, dispatch rules ?  
Author Message
invinfo





PostPosted: 2004-12-29 5:25:00 Top

java-programmer, JSP, forward, include, dispatch rules ? Can I get a clear summary of the rules involved with these ?
forward, include, RequestDispatcher rd

<jsp:include page="servlet/MyServlet" flush="false" />
rd.forward(req, res);
<jsp:forward page="NextPart.jsp" />
response.sendRedirect("NewPage.html");

What I have seen, is that this Error occurs:
'IllegalStateException: Cannot forward after response has been
committed'
When a JSP/Servlet writes to the page using a PrintWriter and then
tries to do a forward.

Maybe the following also cause problems:
response.setContentType(...)
response.setHeader(...)
TIA for your help, suggestions; Please Advise.

 
Ryan Stewart





PostPosted: 2004-12-29 13:03:00 Top

java-programmer >> JSP, forward, include, dispatch rules ? <email***@***.com> wrote in message
news:email***@***.com...
> Can I get a clear summary of the rules involved with these ?
> forward, include, RequestDispatcher rd
>
http://www.jcp.org/aboutJava/communityprocess/final/jsr154/

It's pretty clear.

> <jsp:include page="servlet/MyServlet" flush="false" />
> rd.forward(req, res);
> <jsp:forward page="NextPart.jsp" />
> response.sendRedirect("NewPage.html");
>
Do you really expect all that to work?

> What I have seen, is that this Error occurs:
> 'IllegalStateException: Cannot forward after response has been
> committed'
> When a JSP/Servlet writes to the page using a PrintWriter and then
> tries to do a forward.
>
Not accurate.

> Maybe the following also cause problems:
> response.setContentType(...)
> response.setHeader(...)
> TIA for your help, suggestions; Please Advise.
>
A response is considered committed when any part of it has been sent to the
client. After a response is committed, certain things may not happen, such
as setting response headers (should be obvious), forwarding, redirecting,
and resetting the response. Do you have a specific question? We'd be happy
to entertain.