This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to avoid IllegalStateException (Response Already Commited )

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to avoid IllegalStateException (Response Already Commited )

Hi

I am having a jsp page in which , depending upon the action from the user i need to transfer the control to a different page

For example




But unfortunately i am getting IllegalStateException (Response Already Commited )

I had tried using RequestDispatcher , jsp:forward , sendRedirect , but everything results in same Exception


Please tell me what how can i successfly transfer the control

Anybody help from you would be greatly useful
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't if the response is already committed. Sounds like you are trying to implement your control logic in the wrong place.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
means what are the steps i need to follow to make it that code executed .please tell me
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to move your code to a place where it can run before the response has been commited.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


THnaks paul , THe jsp page is developed in 2006 and it nearly consists of 3000 lines of code .

I don't know what to do .
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, a 3000 line JSP file is a huge problem that you should probably fix before moving forward. Use the jsp only for output. Try to put things like redirects in the servlet code.

"Response Already Committed" is telling us that the response has already started to write and you are trying to modify it. So, whatever you are trying to do, you must do it earlier, before anything has been written to the response.

look at this for more info
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common cause of this problem is simply having a space or carriage return at the top of the JSP. For example, if you have some page directives separated by carriage returns, then those may be put into the response body. Then, if your JSP tries to set something in the header, such as the document type, an exception is thrown. (Remember that the response is just a stream -- the JSP container can't back up and write header data after the page has already started writing the body.) So verify that there are no spaces or carriage returns anywhere in the page above the scriptlet. (There can be carriage returns and spaces within the page directives or scriptlets.) Don't even start the scriptlet "<%" on its own line, since that would mean you'd have a carriage return in the page before the scriptlet code is encountered.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Max, please let me know what is meant by carriage returnds ??
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran Varre wrote:Max, please let me know what is meant by carriage returnds ??

The "return" key. A blank line. Vertical whitespace. CR/LF.

The nutshell version is that you can't redirect/etc. after something's been written to the response, including whitespace.

Echoing an earlier comment: a 3000-line JSP is a horrible idea, and should be fixed, or you will simply continue having difficult-to-diagnose and difficult-to-repair problems.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, David ,Max ,Tim for suggestions.

I somehow solved it by using



kept this in the middle of the jsp

Most common problem so wanted to share the code
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in the middle of a 3000-line JSP, you automatically submit the form without the page having much, if any time to be displayed? What's the point of the rest of that JSP? Is it all Java code?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean in midle of the page means

if(action.equals("blowup")
{
---
---some code

<script>
document.formname.action="jsp page ";
</script>

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic