File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes  java.lang.IllegalStateException: 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 » JSP
Bookmark " java.lang.IllegalStateException: getOutputStream() has already been called for this response" Watch " java.lang.IllegalStateException: getOutputStream() has already been called for this response" New topic
Author

java.lang.IllegalStateException: getOutputStream() has already been called for this response

raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
hi to all,

i am trying to export some data from my project to excel file....while clicking on the icon i am getting the following error.....(i am using jboss with apache clustering on windows 7 in myeclipse ide)


Servlet.service() for servlet action threw exception: java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:598) [:6.1.0.Final]
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:199) [:6.1.0.Final]
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125) [:6.1.0.Final]
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118) [:6.1.0.Final]
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188) [:6.1.0.Final]
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:117) [:6.1.0.Final]
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:76) [:6.1.0.Final]
at org.apache.jsp.pages.MozartCostLoginAdmin_jsp._jspService(MozartCostLoginAdmin_jsp.java:86)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [:6.1.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [:6.1.0.Final]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [:6.1.0.Final]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [:6.1.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:734) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:541) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:479) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [:6.1.0.Final]
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063) [:1.2.7]
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386) [:1.2.7]
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229) [:1.2.7]
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) [:1.2.7]
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [:1.2.7]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at com.zyom.security.LoginMonitorFilter.doFilter(LoginMonitorFilter.java:67) [:]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:504) [:6.1.0.Final]
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:437) [:6.1.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
at java.lang.Thread.run(Thread.java:619) [:1.6.0_13]






R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 370
    
    1

Do you really expect someone to read your complete code and tell you where you went wrong??
I bet even you wouldn't take pleasure to re-read your code to find out where the problem is..

At least you should tell at what point you are getting exception..

Read UseCodeTags and SSCCE
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
actually it is working on jboss 4.2.2 server.....after that recently i clustered jboss with apache server....then onwards i am getting this error.....

I reviewed the entire code but its difficult to find where the problem is ....thats why i posted entire code......if i found where the problem is then no need to ask for suggestions....

Thanks for the reply.....suggest me if any solution for this one..
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 370
    
    1

raghu tammina wrote:actually it is working on jboss 4.2.2 server.....after that recently i clustered jboss with apache server....then onwards i am getting this error.....

I reviewed the entire code but its difficult to find where the problem is ....thats why i posted entire code......if i found where the problem is then no need to ask for suggestions....

Thanks for the reply.....suggest me if any solution for this one..

Can you edit your code to add Code Tags... I gave you the link showing how to in my previous post..
It would be easy for someone knowing the answer to read your code and answer it..
Else I am sure everyone will be doing what I am doing.. Just see your code and move back to next post without even bothering to read it...

So, you are losing a bundle full of experts comments on your post.. And that we don't want to happen in JavaRanch
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
yeah!

i done what you suggest...

thanks.
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

Before the stream value is passed the operation gets over by the servlet check the file MozartCostLoginAdmin_jsp.java

at org.apache.jsp.pages.MozartCostLoginAdmin_jsp._jspService(MozartCostLoginAdmin_jsp.java:86)


at 86th line what code you had provided. check in java file after the jsp has converted.
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
Hi venkat,

on line number 86 in MozartCostLoginAdmin_jsp.java i found this code.Tell me what is the problem here? suggest me how to solve this issue?

_jspxFactory.releasePageContext(_jspx_page_context);

please the code
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

problem is in downloading part as you might not handled it properly. try to debug your downloading stream part again.

Also at some cases the release of the objects used in the jsp will call response.getWriter () because of this method and response.getOutputStream () this conflict may arise
As per line 86 problem


one way to solve it is after you complete the outputstream part add these two lines below that



chances are there to solve it by using these code
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
But the above java file is generated by the container automatically.

how can we add the piece of code to that it is not possible.

is there any way to add the code in jsp?
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

use the code directly in servlet inside the try block .
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
ya done but not works....

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1017
In general, the error message getOutputStream() has already been called for this response is caused by
- issuing a <jsp:forward> or a request.redirect from another page to get to this one after already having committed its response.
- issuing a <jsp:forward> or request.redirect, and then proceeding to send output on the page anyway. After a forward/redirect you should not send any output.

So the problem is possibly not on THIS page, but on the page which is directing you to it.

General rules on forward/redirect in a JSP page
- Don't do it. That sort of logic belongs in the controller which should not be in JSP
- If you DO do it, then make the decision as early as possible in the JSP page, and return directly afterward, so that the JSP doesn't generate enough content to commit the response by filling up the buffer.

raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
Hi stefan,

Please see my jsp code in 1st post.Ididn't use anywhere <jsp:forward>

this code is working fine in jboss 4..2.2. but it is not working in jboss 6.1.0

help me how to solve this issue?tell me the problem where it is in my jsp?
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1017
Yes you are right. In this JSP you haven't used <jsp:forward> or a redirect.
But if you read my post a little more closely, you will see my comment:

the problem is possibly not on THIS page, but on the page which is directing you to it.


HOW do you GET to this JSP?
What triggers this JSP being called?

Looking at your stack trace, you make a request to a struts action.
Which then FORWARDS to this JSP.
No surprises there. That's what a standard struts request does.


The question is which struts action is being invoked?
What ELSE does that action do?
There is no indication in the stack trace what that action is (its just standard struts handler code)

You intimated that this exception was triggered by pushing the "convert to excel" button?
Why would pushing that button end up invoking this jsp? Shouldn't it be returning an Excel file? If it returns an Excel file it can't also return an html response...
The answer should be in your struts config somewhere.

raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 59
Hi stefan,

When i am clicking the button it calls to the following action class-----> it is not return any html response.

<action attribute="mapCustomerForm" name="mapCustomerForm"
path="/regionCustUserMapXl" scope="request"
type="com.zyom.struts.ats.action.RegionCustUserMapXlAction" />

and actual jsp page configuration in struts config file.


<action path="/regionCustUserMap" scope="request" parameter="method"
name="mapCustomerForm" type="com.zyom.struts.ats.action.AtsRegionCustUserMapAction">
<forward name="show" path="/ats-pages/AtsRegionCustUserMap.jsp" />
</action>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.IllegalStateException: getOutputStream() has already been called for this response