aspose file tools*
The moose likes Struts and the fly likes java.lang.IllegalStateException: getOutputStream() has already been called for this response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "java.lang.IllegalStateException: getOutputStream() has already been called for this response" Watch "java.lang.IllegalStateException: getOutputStream() has already been called for this response" New topic
Author

java.lang.IllegalStateException: getOutputStream() has already been called for this response

raj som
Greenhorn

Joined: Dec 19, 2011
Posts: 3
Hello all,

I have this code to create a file and then provide a save option to download the file using a file save dialog box.
I have gone the forum and searched for solutions to the problem. I tried the solutions provided but could not make it work.
The code works fine till it hits return forward [line 50]
I use tiles to display the web pages.
please help.

I get the following error:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:607)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:122)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:173)
at org.apache.struts.tiles.taglib.InsertTag$InsertHandler.doEndTag(InsertTag.java:893)
at org.apache.struts.tiles.taglib.InsertTag.doEndTag(InsertTag.java:465)
at org.apache.jsp.jsp.PubsWebLayout_jsp._jspx_meth_tiles_005finsert_005f0(PubsWebLayout_jsp.java:201)
at org.apache.jsp.jsp.PubsWebLayout_jsp._jspService(PubsWebLayout_jsp.java:140)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:565)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:493)
at org.apache.struts.action.RequestProcessor.doInclude(RequestProcessor.java:1105)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:292)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:271)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:332)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.usairways.ilearning.framework.controller.SessionFilter.doFilter(SessionFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)


Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Usually we get this error if you are doing something after response has committed.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
raj som
Greenhorn

Joined: Dec 19, 2011
Posts: 3
Mohan Rao Sv wrote:Usually we get this error if you are doing something after response has committed.


thanks mohan,

the intention is to return to the same page once the 'save' button has been clicked.
I am returning back to the same page


please let me know how to solve the issue.
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Do not forward it to the same view. Just return nothing(forward = null). The user would still be in the same view(JSP) which would solve the problems(exception & view part).

-(not for this issue) Additionally, also flush the streams and use "finally" [Make this a rule] to close the resources(streams) for avoiding further problems in future.



Have Fun with Java
little,little.. little by little makes a lot..
raj som
Greenhorn

Joined: Dec 19, 2011
Posts: 3
Shankar Tanikella wrote:Do not forward it to the same view. Just return nothing(forward = null). The user would still be in the same view(JSP) which would solve the problems(exception & view part).

-(not for this issue) Additionally, also flush the streams and use "finally" [Make this a rule] to close the resources(streams) for avoiding further problems in future.



worked great.
also, I am now flushing the streams and closing them in finally block.
many thanks Shankar!
 
 
subject: java.lang.IllegalStateException: getOutputStream() has already been called for this response