This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes Redirect Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Redirect Error" Watch "Redirect Error" New topic
Author

Redirect Error

Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
Hello,

I am redirecting to page after doing some process, however I am getting error:


IllegalStateException: Response has already been committed, be sure not to write to the OutputStream or to trigger a commit due to any other action before calling this method.

How can I solve this?

Thanks in advance.

Cosmos


Never take anything for granted because you never know when you will lose it
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Make sure you redirect before anything has been written, including headers.
Then return right after the sendRedirect.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
I tried giving a return after the redirect, but still it throws that error.

I have lot of html statements before the redirect, does that cause any problem?

Cosmos
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
You had better come up with code snippet.
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hello,

U said that there are lot of html statements before redirect. This means that you are writting to the response. There may be a situation in your case that the response is alredy committed ( output is written to the response and it is flushed). Therfore it is throwing an Exception.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Make sure you redirect before anything has been written, including headers.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
You can use a response wrapper to cache the response data in memory (ByteArrayOutputStream) and write it out at the end when you're sure that everything went as planned.


James Carman, President<br />Carman Consulting, Inc.
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
Ok I will try or I will remove all html code and see whether it works or not, I beleiev if it's only JSP code, it should work without throwing any excpetions.

Cosmos
Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
OK I removed all the html codes and it worked. I am using this page only for inserting and for calling a stored procedure.

Thanks to everyone for all help. Much appreciated.

Cosmos
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirect Error