This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Error: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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Error:getOutputStream() has already been called for this response" Watch "Error:getOutputStream() has already been called for this response" New topic
Author

Error:getOutputStream() has already been called for this response

Neha k Agrawal
Greenhorn

Joined: Mar 25, 2008
Posts: 25
Hello everyone,
I have integrated Jasper Reports with Struts 1.2.9.At runtime I am getting this error.

ApplicationDispatcher[/TGMC_DB1-2009] PWC1231: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response

at org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:700)
at org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:210)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:135)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:171)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:164)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:221)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:157)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:108)
at org.apache.jsp.LeftMenu_jsp._jspService(LeftMenu_jsp.java from :152)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)


I read that "It is just that we open a output stream in the action and when we forward to any jsp, the container tries to open an output stream to write the JSP contents".So I have tried returning null instead if any action in my action class.Still it is giving same error.Please help me experts.Any help will be Highly Appreciated.

This is my code in action class.The line which is generating error is in bold... one more thing after exception it is going in 2nd catch block & not in first catch block where ex.getMessage() is printing null.

Steven Lawrence Hunter
Greenhorn

Joined: Apr 17, 2008
Posts: 4
This is an old thread, but in case someone happens by here, like I did, researching the same problem, I thought I'd share.

The basic problem is that you get the response's output stream inside the try block, and then again in the catch block of the JRException. So if you raise a JRException while running a report, the attempt to log the problem will result in the illegal state exception you're seeing. Rewrite your code to scope your ServletOutputStream servletOutputStream variable outside the try so it will be available inside the catch.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error:getOutputStream() has already been called for this response