aspose file tools*
The moose likes JSP and the fly likes 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 "IllegalStateException: getOutputStream() has already been called for this response" Watch "IllegalStateException: getOutputStream() has already been called for this response" New topic
Author

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

shashi bhushans
Greenhorn

Joined: May 12, 2011
Posts: 17
Hi All,
In Work Detail Module, 3 sub modules are--> 1.create, 2.update, 3.correct.
In CREATE Work Detail page, i ll add data and upload photos of work details in createworkdetail.jsp. photos ll stored in D:\CMSMTDP_WorkDetailImages\Anekal\n1.jpeg
In updateworkdetail.jsp & correctworkdetail.jsp(see attached screen pics) if i click on image it ll show error(refer getOutputStream already response.txt) but image is visible n pop in new window.

code for downloaded file(D:\CMSMTDP_WorkDetailImages\Anekal) & to view in jsp

public static void downloadFile(String fileName,HttpServletResponse res) throws WebException
{
ServletOutputStream outStream = null;

int bytesRead=0;
byte [] byteArray = new byte[4096];
System.out.println("filename===>"+fileName);
if(null != fileName)
{
try
{
System.out.println("inside prior to execution download");
FileInputStream is=new FileInputStream(new File(fileName));
res.setContentType("image/jpeg");
outStream = res.getOutputStream();
bytesRead = is.read(byteArray);
while (bytesRead!= -1)
{
outStream.write(byteArray, 0, bytesRead);
bytesRead = is.read(byteArray);
}

// Flush and close stream
outStream.flush();
outStream.close();
is.close();
}
catch (FileNotFoundException e)
{
//throw new WebException(e);
e.printStackTrace();
}
catch (IOException e)
{
throw new WebException(e);
}
}

}
error getting in console:
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:610)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:173)
at org.apache.struts.tiles.taglib.InsertTag$InsertHandler.doEndTag(InsertTag.java:893)
at org.apache.struts.tiles.taglib.InsertTag.doEndTag(InsertTag.java:465)
at org.apache.jsp.jsp.Common.CommonLayout_jsp._jspx_meth_tiles_005finsert_005f0(CommonLayout_jsp.java:188)
at org.apache.jsp.jsp.Common.CommonLayout_jsp._jspService(CommonLayout_jsp.java:145)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:630)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
at org.apache.struts.action.RequestProcessor.doInclude(RequestProcessor.java:1110)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:292)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:271)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:332)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at in.gov.mrc.kstd.arch.web.WSSORequestFilter.doFilter(WSSORequestFilter.java:141)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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:128)
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:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)



[Thumbnail for CreateWorkDetail.jpg]


[Thumbnail for UpdateWorkDetail.jpg]


[Thumbnail for CorrectWorkDetail.jpg]

Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi,

Please check link1,link2,link3,link4

Thanks


The important thing is not to stop questioning.Curiosity has its own reason for existing.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
What's the relationship between the code you posted and JSP? The code writes something to the OutputStream, which means you can't forward to a JSP afterwards (if that's what you're doing, the code you posted doesn't show the complete flow of control).


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateException: getOutputStream() has already been called for this response