This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
CreateWorkDetail.jpg
[Thumbnail for CreateWorkDetail.jpg]
createworkdetail jsp page
UpdateWorkDetail.jpg
[Thumbnail for UpdateWorkDetail.jpg]
update work detail jsp page
CorrectWorkDetail.jpg
[Thumbnail for CorrectWorkDetail.jpg]
correct workdetail jsp page
 
Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please check link1,link2,link3,link4

Thanks
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Level Up Your Code with a Pro Java IDE
https://www.jetbrains.com/idea
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!