java.lang.IllegalStateException: getOutputStream() has already been called for this response(java.lang.IllegalStateException: getOutputStream() 已经为此响应调用)
问题描述
这是我得到以下异常的代码
Here is my code for which I am getting the following exception
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 看起来像这样:
My Struts.xml looks like this:
<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 中,我只是给出了一个按钮,它提供了 open, save 对话框.单击该按钮后,我得到了异常.
In JSP, I am just giving a button which gives me open, save dialog box.
After clicking that button I am getting the exception.
如何避免这种情况?
推荐答案
删除关闭 %> 和打开 <% 之间的所有空格和换行符和在顶部使用 <%@page trimDirectiveWhitespaces="true" %> 可以解决这个问题.
Remove all space and linebreaks between closing %> and opening <% and use <%@page trimDirectiveWhitespaces="true" %> at top can solve this issue.
这篇关于java.lang.IllegalStateException: getOutputStream() 已经为此响应调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java.lang.IllegalStateException: getOutputStream() 已经为此响应调用
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
