Hi,
I m following this
thread and i have a similar requirement where I have to enable client to download a data from the database into a file.
After I get the data I don't want to save that data into a file on the server and then give that file for download but just pass that data over ServletOutputStream and allow user to copy that data in a file on client machine.
I wrote a sample program
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
[ September 10, 2004: Message edited by: Saritha ventrapragada ]