Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JSP forward not working

 
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
 
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.
 
Rancher
Posts: 43016
76
  • 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.
 
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.
 
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.....
 
What's brown and sticky? ... a stick. Or a tiny ad.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic