Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect causes llegalStateException?

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i run on the code as follow :


it give me java.lang.IllegalStateException
at org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteRes
ponseFacade.java:352) error ,

what would normally cause by this error ? i have testing-details.jsp in the page folder ..thank you for guidance
[ January 23, 2006: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, most likely, that your jsp is still trying to print to the outstream after you've send a redirect to the browser.

Neither response.sendRedirect nor requestDispatcher will halt the execution of your servlet/jsp service method.
You need to do it explcitly.





Alternatively, you could branch your code in such a way that the call to redirect is always at the end of the brach.
[ January 23, 2006: Message edited by: Ben Souther ]
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ben for reply ..but the problem remain same
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can also be caused by emitting output before a redirect (or a forward). It's usually an indication of a poorly structured application.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can, post the whole script.
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ben , the code have many lines , which more than few thousand lines, i do agree we are using poor structure application, imagine the application only use jsp page for logic part, it was developed many year ago, it seem hard to maintain
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel your pain.

The things to look out for are to make sure that you return (as Ben said) after any redirect or forward, and to be sure that any redirect or forward decision is made before emitting any output to the buffer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic