• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP forward not working

 
vani ruddarraju
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used JSP forward at the bottom of my 500+ lines of code jsp page.

Gave this error:



Then, i put this thing at the top:

Now it works!

Can someone please explain the reason behind that?

Thanks!
Vani
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/RequestDispatcher.html#forward%28javax.servlet.ServletRequest,%20javax.servlet.ServletResponse%29

When you forward a request to another resource.. whose response is already commited.. then it throws this exception.
A request that is being forwarded should not have commited.

In your case, when the JSP is being executed, it might have generated some html content before it is forwarding.

If the server has send these html content to a client before you forward the request to another resource, then it throws an illegal state exception if you try to forward.

As you increased the buffer size, then the server is not actually sending the generated html content to client (Till the buffer fills up).. and on forward the buffer will be cleared.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forwarding or redirecting should not be done in JSP - that's the job of servlets. JSPs are for creating textual output, not for containing any logic or Java code.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, increasing the buffer size didn't solve the problem, it just hid it better. You should never forward after sending some response to the client. If your code is forwarding after sending some response to the client, it is broken and should be fixed.
 
Anup Mulik
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vani ruddarraju wrote:I used JSP forward at the bottom of my 500+ lines of code jsp page.

Gave this error:



Then, i put this thing at the top:

Now it works!

Can someone please explain the reason behind that?

Thanks!
Vani



Thanks boss you rock ,same was a case with me . I was having a jsp with 1200 lines of code and my fwd was not taking place . I tried to find out wat is wrong again and again , but nothing was working .At last it's JAVA RANCH where my search end postive.
You saved me yar.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!