This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP: IllegalStateException problem

 
Tiago Massoni
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people,
See if you can help me out. I am having this problem in my web application. Sometimes when I have more than one user using some pages, I have this error:
X Servlet Error: ERROR: Cannot forward. Writer or Stream already obtained.: java.lang.IllegalStateException
The error page sometimes is not called for this error, what makes it stranger for me (I am not a JSP advanced programmer).
Has somebody had a similar problem?
Thanks in advance,
Tiago.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your code do any forwarding? If so, to what?
You get this error if your JSP has already sent some response text (and the response buffer has been flushed) before the forward takes place.
The reason being that whatever you forward to may want to discard the existing output buffer with resetBuffer.
A possible cure would be to set a larger buffer size for the page.
Bill
 
Sandeep. Oza
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tiago,
I have also getting the same problem when forwarding to curom error page.
Bill,
you are suggesting to increase buffer size ...
dear, the page is dynamically generated.. content is not fixed.. and if we use more buffer, i think it is improper utilization of server resources..
Pl. let me know if you get the solution on sandeepo@bsil.com
S. Oza
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bill,
you are suggesting to increase buffer size ...
dear, the page is dynamically generated.. content is not fixed.. and if we use more buffer, i think it is improper utilization of server resources..

Never-the-less, what I said is the cause and the cure. If your JSP may generate more than one bufferload of output before forwarding, thats what is going to happen.
Increasing the buffer size is a perfectly reasonable solution - why do you think that method is in there if not to accommodate this situation? It does not permanently use memory since the buffer is in the response object which is discarded or recycled.
An alternative is to re-factor your JSP so that large and/or variable amounts of text are not written to the output before forwarding.
Bill
 
Tiago Massoni
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!
Thanks for the replies...that's exactly the problem, I am not using jsp:forward on any file of my application!!
I suspect the problem is with the error page...I think when the system calls the error page, it's considered a forwarding. Am I right?
Thanks!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right - that is one of the obstacles to making use of an error page, if the output has been flushed already, it generates a new error that obscures the cause of the original error. Temporarily jacking up the buffer size should give you a chance to isolate the error.
Bill
 
Biswajit Jena
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Willy,
I also et the same error. Can you tell me how do i solve this error ?
I have increased the buffer size. now will it solve my problem ?
Regards
Biswajit
Originally posted by William Brogden:

Never-the-less, what I said is the cause and the cure. If your JSP may generate more than one bufferload of output before forwarding, thats what is going to happen.
Increasing the buffer size is a perfectly reasonable solution - why do you think that method is in there if not to accommodate this situation? It does not permanently use memory since the buffer is in the response object which is discarded or recycled.
An alternative is to re-factor your JSP so that large and/or variable amounts of text are not written to the output before forwarding.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic