Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic