File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes sendRedirect causes llegalStateException? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "sendRedirect causes llegalStateException?" Watch "sendRedirect causes llegalStateException?" New topic
Author

sendRedirect causes llegalStateException?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
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

Joined: Dec 11, 2004
Posts: 13410

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 ]

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

Joined: Apr 13, 2005
Posts: 442
thanks ben for reply ..but the problem remain same
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61755
    
  67

This can also be caused by emitting output before a redirect (or a forward). It's usually an indication of a poorly structured application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you can, post the whole script.
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
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

Joined: Jan 10, 2002
Posts: 61755
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sendRedirect causes llegalStateException?