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 response.sendRedirect giving illegalStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "response.sendRedirect giving illegalStateException" Watch "response.sendRedirect giving illegalStateException" New topic
Author

response.sendRedirect giving illegalStateException

Kshitiz Agarwal
Ranch Hand

Joined: Dec 15, 2011
Posts: 36
Hi,

I am trying to learn JSP. I am trying to code a simple page with a form submission. The code is:





imageUploader.jsp




The code is really simple but I dont understand why I am getting the error:

java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
at org.apache.jsp.imageUploader_jsp._jspService(imageUploader_jsp.java:139)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)




Please help me out here...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

from sendRedirect Javadoc :

If the response has already been committed, this method throws
an IllegalStateException.
After using this method, the response should be considered
to be committed and should not be written to

you are including a jsp to show to user, immediately redirecting to other page which defeat the purpose of include action.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Specifically the flush="true" attribute is flushing the buffer, and committing the response.

You either need to
- remove the flush="true" attribute
- put the response.redirect earlier in the code

Another thing you may need to know.
Just because you TOLD the server to redirect the response doesn't mean the current page stops running
After issuing a forward/redirect, you should immediately return from your page.
Standard approaches:


or


Kshitiz Agarwal
Ranch Hand

Joined: Dec 15, 2011
Posts: 36
Stefan Evans wrote:Specifically the flush="true" attribute is flushing the buffer, and committing the response.

You either need to
- remove the flush="true" attribute
- put the response.redirect earlier in the code

Another thing you may need to know.
Just because you TOLD the server to redirect the response doesn't mean the current page stops running
After issuing a forward/redirect, you should immediately return from your page.
Standard approaches:


or




Thank you....You have solved the problem..:)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: response.sendRedirect giving illegalStateException
 
Similar Threads
Regarding my project
Struts2-jQuery Plugin
Can not retrieve definition for form bean null on action
tomcat cannot display jsp struts
Could not retrieve data using JSTL