This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

getOutputStream() has already been called for this response  RSS feed

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting the folllowing exception when I try to generate a pdf


java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:611)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:122)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:187)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:180)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:237)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:173)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:124)
at org.apache.jsp.pages.common.GeneratePdf_jsp._jspService(org.apache.jsp.pages.common.GeneratePdf_jsp:256)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

My code is:



I googled and found no solution.

Some one is saying to return null. some one is saying call the action through another jsp, another is saying call the servlet directly.

Actually I didnt understand what exactly is that. Action class is nothing but a Servlet. I tried returning null also. I used another jsp to call action but it didnt avoid the exception. I dont know where I am going wrong.

Please guide me how to avoid it. As I have to return some success message also after generating the pdf so I cant return null. With the above code I am able to gnerate the pdf but not able to get rid that exception and aslo I am not able to display the success msg in the jsp.

Thanking you.

-- raaja. g
 
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raaja,
Please close your servlet output stream, which would solve your problem. and close it finally
Caution:: Never catch a generic exception as above,
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The problem still persists. If I set return null in the action the exception is not coming. And also another problem came as it is a web application If I access from client machine and try to generate pdf its giving message format error:not a PDF or corrupted. If the same application deployed and run from local machine (os: winxp) it perfectly generates the pdf.

Where I am going wrong. Please correct me.

Thanking you.

--raaja. g
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting the java.lang.IllegalStateException: getOutputStream() has already been called for this response when I use return map.findForward("success"); at the end of action class. But this exception wont appear if I return null. But this will not display an error message in the jsp through action messages.

How to avoid the above said exception so that I can generate a pdf when success and print a message when failed.

My code is:

 
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you return "success" at any cost? Why don't you use appropriate return statements for failure of PDF generation and other cases? In case your PDF generation was successful, returning null doesn't cost you a fortune, does it? I stress this because,

Oh wait, it's rather worth quoting this:

Basic rule of HTTP: one request, one response.

You can only send back one thing to a request.
Either an HTML page, or a PDF document, or an image or....
Specifically you can't send an HTML page AND a PDF document.
Java complains if you have already obtained a writer/outputstream as you should only be getting ONE of these.



This suggests you're trying to forward to a JSP after your action completes, which won't work since you've already sent a PDF back to the browser. Your execute() method should be returning 'null' to tell Struts not to do this.

 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!