Two Laptop Bag*
The moose likes Struts and the fly likes Response has already been committed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Response has already been committed" Watch "Response has already been committed" New topic
Author

Response has already been committed

Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Response has already been committed
 
Similar Threads
deployment problem - struts application
Oc4J webservices
Exception "IllegalArgumentException: Resource not found"
Unsupported major.minor version 49.0
Downloading file through Servlet.