*
The moose likes JSP and the fly likes JSP: IllegalStateException problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP: IllegalStateException problem" Watch "JSP: IllegalStateException problem" New topic
Author

JSP: IllegalStateException problem

Tiago Massoni
Greenhorn

Joined: Feb 18, 2002
Posts: 3
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

Joined: Mar 22, 2000
Posts: 12809
    
    5
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

Joined: Feb 04, 2002
Posts: 66
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


Yes, Everything Is Possible
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5

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

Joined: Feb 18, 2002
Posts: 3
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

Joined: Mar 22, 2000
Posts: 12809
    
    5
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

Joined: Jul 16, 2003
Posts: 1
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


Regards<br />Biswajit Jena
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP: IllegalStateException problem