• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

response.sendRedirect giving illegalStateException

 
Kshitiz Agarwal
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1784
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..:)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic