Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed  RSS feed

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,




Tomcat Log:
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:483)
at LoginDAO.login(LoginDAO.java:108)
at LoginManager.doPost(LoginManager.java:185)


Please advise

Best regards
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is really pretty clear.

Somewhere in your code, enough output is written to the response stream to cause the output buffer to be flushed, sending the response headers - this constitutes commitment of the response since those headers can not be recalled.

So - your task is to figure out where that output gets written.

Bill
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your basic strategy for fixing that error should be to refactor your code. The basic overview of the servlet should be like this:

1. Decide whether it's necessary to redirect.

2. Redirect if it is necessary.

3. Otherwise, continue doing the servlet's actual work, including writing data to the response.

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks all from the bottom of my heart for providing accurate clues. I changed my following servlet part from this code:



To this code:

and problem fixed

Best regards
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!