aspose file tools*
The moose likes Servlets and the fly likes IllegalStateException help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "IllegalStateException help me" Watch "IllegalStateException help me" New topic
Author

IllegalStateException help me

ramu av
Greenhorn

Joined: Feb 25, 2003
Posts: 28
hi all,

i'm using request.sendRedirect("url"); and i'm getting IllegalStateException.

please tell me why we get this Exception so that i can correct it.

here is the code snippet. please tell me what i should do.
haitham raik
Greenhorn

Joined: Aug 08, 2004
Posts: 17
Dear ramu,
this type of exceptions occur in in one of the following two cases:
1. If the response was committed.
2. if a partial URL is given and cannot be converted into a valid URL.
so, to solve this problem follow the following steps:
1. validate the URL parameter to be relative to the current page and the page that you want to redirect to is exist and valid.
2. may be you have committed your output by using res.flush() method. if so you have to remove this statement from your code.
3. if your code placed in JSP page. I think you have used the page directive with attribute buffer="none".
3. if you have kept the buffer attribute without changing try to make it's value bigger, for example buffer="32kb"

the last thing that I want to say that the It is illegal to set autoFlush to false when buffer=none.

Regards


Haitham Raik<br />SCJP 1.4 SCWCD 1.4 SCBCD 1.3 SCJA 1.0
ramu av
Greenhorn

Joined: Feb 25, 2003
Posts: 28
hi haitham raik
response.sendRedirect("<target URL>");
is working fine for the first time execution by the server.
but on revisit to this servlet it results in IllegalStateException
i'm not using JSP so buffer issue does not come into picture. I have not even used res.flush();
So please help me out.
louise rochford
Ranch Hand

Joined: Apr 04, 2002
Posts: 119
Hi Ramu,

is working fine for the first time execution by the server.
but on revisit to this servlet it results in IllegalStateException



Is it possible that the session has timed out? You can get an IllegalStateException if the session has become invalid. When you say "on revisit" do you mean when the redirected request comes in from the client, or when you invoke the method some time later?

Maybe you could post the top section of your stack trace so we can see the exception more clearly?

Regards,
Louise
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
response.sendRedirect("<target URL>");
is working fine for the first time execution by the server.
but on revisit to this servlet it results in IllegalStateException
i'm not using JSP so buffer issue does not come into picture. I have not even used res.flush();
So please help me out.

Alas - whether or not you are using JSP has nothing to do with it. It is the underlying servlet output buffer - which is flushed when full. The first flush of the output buffer sends the response headers - if you try to do a redirect AFTER the headers are sent, you get the IllegalStateException. This is because a redirect is done with the response headers.
Probably the second visit results in slightly more output, thus causing the flush.
Ideally your servlet should determine the necessity for a redirect before ANY output has been written. If this is impossible, set the response buffer size larger.
Bill


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateException help me
 
Similar Threads
Stack Over flow error when Instantiating
How to create close buttons
return -1. why ???
Adding int value in to a session
Inner Class - Help Required