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 servletjsp 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.
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.