HTTP Status 500 - Unable to show problem report: java.lang.IllegalStateException: getOutputStream() has already been called for this response
代码:
WorkbookSettings wbSettings = new WorkbookSettings();
OutputStream outStream = null;
try
{
wbSettings.setLocale(new Locale("en", "EN"));
response.setContentType("application/vnd.ms-excel");
outStream= response.getOutputStream();
response.setHeader("Content-Disposition", "attachment; filename=/timesheet.xls");
WritableWorkbook workbook = Workbook.createWorkbook(outStream, wbSettings);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
service.createLabel(excelSheet);
service.createContent(excelSheet);
workbook.write();
workbook.close();
outStream.flush();
outStream.close();
}
catch(Exception e)
{
}
finally
{
//outStream.close();
}
return "generateReport";
我的struts.xml
如下所示:
<result type="stream" name="generateReport">
<param name="contentType">"application/vnd.ms-excel"</param>
<param name="inputName">excelstream</param>
<param name="contentDisposition">contentDisposition</param>
<param name="bufferSize">1024</param>
</result>
在JSP中,我只是给出了一个按钮,它给出了打开,保存
对话框。单击该按钮后,我将获得异常。
如何避免这一点?
这只是一个语法错误,服务器在困惑如何处理这样的内容类型
<param name="contentType">"application/vnd.ms-excel"</param>
更改为
<param name="contentType">application/vnd.ms-excel</param>
注意,param
值是一个没有双引号的字符串。
<result type="stream" name="generateReport">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">attachment;filename="timesheet.xls"</param>
<param name="inputName">excelstream</param>
</result>
private InputStream excelstream;
public InputStream getExcelstream() {
return excelstream;
}
public String execute() throws Exception {
WorkbookSettings wbSettings = new WorkbookSettings();
try {
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(outstream, wbSettings);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
service.createLabel(excelSheet);
service.createContent(excelSheet);
workbook.write();
workbook.close();
excelstream = new ByteArrayInputStream(outstream.toByteArray());
} catch(Exception e) {
e.printStackTrace();
throw e;
}
return "generateReport";
}
我正在做关于CXF和Spring的培训,所以我写了一个非常简单的CXF演示,其中只有接口“HelloWorld”和它的实现者“HelloWorldWs”。 我想用Tomcat发布它。我编写了web.xml和applicationcontext.xml(Spring配置文件。虽然我可以发布WSDL。但是控制台列出了一个问题: 我没有使用或编写任何io函数,只是一个“sayhi”函数。我被难倒了。
稍后,在同一个JSP中,我调用一个方法,该方法最终调用jasper-reports: HttpServletResponse对象“Response”被传递给以下方法,在调用时发生错误: 我已经查看了以下堆栈溢出帖子,仍然需要一些关于如何修复此问题的指导:
由于我想下载文件,所以不得不使用。 但我遇到以下异常:
最大的问题是,对于以下异常,代码片段可以正常工作。用户可以将文档保存在所需的位置。我想弄清楚为什么我会得到这个错误。