File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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

Neha k Agrawal

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(
at org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(
at javax.servlet.ServletResponseWrapper.getWriter(
at org.apache.jasper.runtime.JspWriterImpl.initOut(
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(
at org.apache.jasper.runtime.PageContextImpl.release(
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(
at org.apache.jsp.LeftMenu_jsp._jspService( from :152)
at org.apache.jasper.runtime.HttpJspBase.service(

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

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:
subject: Error:getOutputStream() has already been called for this response
It's not a secret anymore!