• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Response has already been committed

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have posted same problem in servlet forum. I did not get any responses though.

I thought this might be the right place to repost.

I have a requirement to enable client to download a data from the database into a file.

I wrote the following code in Struts Action class.

response.setHeader("Content-Type", "application/comma-separated-values; charset=ISO-8859-1");
response.setHeader("Content-Disposition","attachment;filename=Extract.txt");

ServletOutputStream stream = response.getOutputStream();
String str ="hello world";
byte[] buffer = new byte[str.length()];
buffer = str.getBytes();
stream.write(buffer, 0, str.length());
stream.flush();
stream.close();

with this I am able to open a save/open dialog box onto the broswer and able to save the text in a file but along with the text some exception is also being written into the file.
-------------------------------------------------------------------------
Output:
hello world<PRE>java.lang.IllegalStateException: Response has already been committed
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.EvermindHttpServletResponse.resetBuffer(EvermindHttpServletResponse.java:1901)
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:211)
<br> at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
<br> at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
<br> at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
<br> at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
<br> at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
<br> at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
<br> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:765)
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.AJPRequestHandler.run(AJPRequestHandler.java:208)
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.AJPRequestHandler.run(AJPRequestHandler.java:125)
<br> at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
<br> at java.lang.Thread.run(Thread.java:534)
<br></PRE></BODY></HTML>
----------------------------------------------------------------------------

I would appreciate if you help me in getting rid of that extra information.

Thank you
Saritha
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic