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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
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(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.

 
Greenhorn
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.
reply
    Bookmark Topic Watch Topic
  • New Topic