We have a situation where we need to create a XLS file from a web
application.
The only way we could come up to create the file and have it DL to the
browser
was by forwarding to a servlet. Then the servlet would create the file
and send it to the client. The XLS file would be mapped as a MIME type
in the web.xml.
Problem is, can struts forward to a servlet? If so, what would the
line look like?
<forward name="excel_file" path="/reports/my_servlet"/>
Babu Kalakrishnan - 20 Oct 2005 04:56 GMT
> We have a situation where we need to create a XLS file from a web
> application.
[quoted text clipped - 7 lines]
>
> <forward name="excel_file" path="/reports/my_servlet"/>
Have you tried streaming the output directly to the OutputStream
obtained from the response object (instead of using another servlet) ?
I've had success with something on the lines of :
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition",
"attachment;filename=\"filename.xls\"");
OutputStream out = response.getOutputStream();
response.setContentLength(data.length);
out.write(data);
out.flush();
out.close();
(Assuming that the content to be output is in a byte[] called "data").
Also make sure you return null as the ActionForward from your Action's
execute method so that Struts doesn't try to send out something more to
the response which has already been committed,
BK