Hello,
I hava a form, and after submit it, a POI Workbook object in the form
listener will generate an excel file according to user inputs, and then
return the file to client by means of hooking and writing to the WebResponse
OutputStream.
Everything seems to work well, the workbook object generates and returns
file successfully. But unfortunately, I get the following exceptions in the
tomcat console:
ServletWebResponse:132 - Unable to reset response buffer:
java.lang.IllegalStateException
RequestExceptionReporter:44 - Unable to process client request:
getOutputStream() has already been called for this response
So my question is: How could I return the file in the right way?
P.S. Considering OS privilege and security, I don't think it is good for me
to write the file to file system before returning it to cilent.
CODE of listener:
public IPage export(IRequestCycle cycle) {
try {
WebResponse response =
cycle.getInfrastructure().getResponse();
response.setHeader("Content-Disposition","attachment; filename=data.xls");
OutputStream out =
response.getOutputStream(CONTENT_TYPE); // APPLICATION/OCTET-STREAM.
HSSFWorkbook workbook;
// generate excel file here.
workbook.write(out);
out.close();
} catch (IOException e) {
} catch (ServiceException e) {
}
return null;
}
Any help would be appreciated!
Daniel