java.lang.IllegalStateException:此响应已被调用getOutputStream() [英] java.lang.IllegalStateException: getOutputStream() has already been called for this response

查看:1005
本文介绍了java.lang.IllegalStateException:此响应已被调用getOutputStream()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我收到以下异常

  HTTP状态500  - 无法显示问题报告:java .lang.IllegalStateException:此响应已被调用getOutputStream()

代码:

  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.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(异常e)
{
}
终于
{
//outStream.close();
}
returngenerateReport;

我的 Struts.xml / p>

 < result type =streamname =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中,我只是给出一个打开,保存对话框的按钮。
点击该按钮后,我收到例外。



如何避免这种情况?

解决方案

删除关闭%>之间的所有空格和换行符,并打开<%和
使用<%@ page trimDirectiveWhitespaces =true%>在顶部可以解决这个问题。 p>

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

The code:

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";

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>

In JSP, I am just giving a button which gives me open,save dialog box. After clicking that button I am getting the exception.

How to avoid this?

解决方案

Remove all space and linebreaks between closing %> and opening <% and use <%@page trimDirectiveWhitespaces="true" %> at top can solve this issue.

这篇关于java.lang.IllegalStateException:此响应已被调用getOutputStream()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆