wood burning stoves 2.0*
The moose likes JSP and the fly likes IllegalStateException is coming if I use sendRedirect() method.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "IllegalStateException is coming if I use sendRedirect() method.." Watch "IllegalStateException is coming if I use sendRedirect() method.." New topic
Author

IllegalStateException is coming if I use sendRedirect() method..

Shashi Kala
Ranch Hand

Joined: Jan 27, 2008
Posts: 46
Hi Ranchers,

I am having a HTML page, which is devided as frames. There is 3 frames in this page named as first,left and content. In content frame I have a login page. Here when user clicks on login button, In content frame, some other jsp page should gets displayed(say the jsp page is welcome.jsp).

For this, Previously I have used



But the problem here is..If I login once..it is coming properly. If I click on some other button in another frame and logout..Now in case if I login again an error is coming like..

HTTP Status 500

description The server encountered an internal error() that prevented it from fulfilling this request.

exception

java.lang.IllegalStateException: Cannot forward after response has been committed.
...
...

As shown above the error is coming..So what I did means instead of using sendRedirect() method, I simply assigned the frame location to "/abc/welcome.jsp". Now it is working fine..But I just want to know what was the problem with sendRedirect() method. In which case, the above error will come?

Can anybody make me known..??

Thanks in Advance,
Shashi.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

if you want to use sendRedirect on response. response should not commit already
Shashi Kala
Ranch Hand

Joined: Jan 27, 2008
Posts: 46
response should not commit already

means.. Can you explain in detailed..?
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

java.lang.IllegalStateException: Cannot forward after response has been committed.


The exception itself gives the reason.
And response has been committed means that you have already written the response to the client , so now you dont have control over it.
Please see this FAQ entry for more information.


Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
Shashi Kala
Ranch Hand

Joined: Jan 27, 2008
Posts: 46
Thanks All..

I understood what is happening.
Nishant Kr
Greenhorn

Joined: Aug 07, 2008
Posts: 8
Hi Shashi,

It'll be better if you use

<jsp:forward page ="("/abc/welcome.jsp"/>

in place of

response.sendRedirect("/abc/welcome.jsp");

after checking all the necessary conditions for the login stuff.
This tag doesn't notify the browser about the new page. The new page is opened but you need to notice that the address in the address bar remains the same.

Thank You,
Nishant
Nishant Kr
Greenhorn

Joined: Aug 07, 2008
Posts: 8
<jsp:forward page ="/abc/welcome.jsp"/>
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Hi Nishant Kr welcome to Javaranch ,
If you want to edit a post(posted by you of course), then you can do it by simply clicking the icon.

Hope this helps
[ August 07, 2008: Message edited by: Amit Ghorpade ]
Nishant Kr
Greenhorn

Joined: Aug 07, 2008
Posts: 8
Mr Ghorpade,

Can you please answer to the topic...? If you don't have that much of ability or kind nature to help somebody, you better be in peace. I find most of your forums to be useless....!

Thank you
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Originally posted by Nishant Kr
Can you please answer to the topic...?

Its already posted above by me.

If you don't have that much of ability or kind nature to help somebody, you better be in peace.

Do you have any good reason to say that? If yes please let me know.
But anyways I dont think you are supposed to tell what I should do.
I find most of your forums to be useless....!

I dont have any forum
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

"Nishant Kr", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: IllegalStateException is coming if I use sendRedirect() method..