java导出excel报错:getOutputStream() has already been called for this response
对于java导出excel报错的问题,查了很多都说是在使用完输出流以后调用以下两行代码即可
out.clear();
out = pageContext.pushBody();
但这也许是页面上输出时可能犯的错,最后查了很多,终于解决,具体方法如下:
这个下载excel的方法返回一个ActionForword对象,比如:

而response是ActionForword对象的参数,所以就会使response冲突,所以,解决的办法有:
第一种:return null,
第二种:将返回参数改为void,去掉返回值,也就是将上面的代码修改如下:
public void downloadFile(){
try{
ExportInfo exportInfo = exportInfoService.getExportInfo(exportId);
setAttribute("exportInfo", exportInfo);
File file = new File(exportInfo.getFilePathname());
if (file.exists()) {
HttpServletResponse response =ServletActionContext.getResponse();
DownloadUtil.downloadFile(file.getName(), file, response);
//file.delete();
}
} catch (DolException e) {
logger.error(e.toString(), e);
} catch (Exception e) {
logger.error(e.toString(), e);
}
}
注:本人推荐使用第二种
java导出excel报错:getOutputStream() has already been called for this response的更多相关文章
- weblogic 12c下jxls导出excel报错Could not initialize class org.apache.poi.xssf.usermodel.XSSFVMLDrawing
周一,开发反馈weblogic 12c下jxls导出excel报错,公司环境和UAT环境均报错,看日志如下: 2016-06-08 09:16:55,825 ERROR org.jxls.util.T ...
- JSON.toJSONString(joinPoint.getArgs())报错getOutputStream() has already been called for this response
nested exception is java.lang.IllegalStateException: It is illegal to call this method if the curren ...
- easyPOI导出excel报错
http-nio--exec- at :: - excel cell export error ,data is :com.jn.ssr.superrescue.web.qc.dto.Automati ...
- asp.net 发布后,遇到的导出excel报错的问题
做的asp.net程序,最近要发布在外网上,发布过程不太难,网上都有现成的,只要按照相应的步骤基本都不会有什么问题,关键是发布成功后,程序中涉及到excel的导出或者导入问题,就会提示“检索COM 类 ...
- 导出excel报错
System.ComponentModel.Win32Exception: 拒绝访问 1.问题现象: foreach (System.Diagnostics.Process thispro in Sy ...
- php 导出 Excel 报错 exception 'PHPExcel_Calculation_Exception' with message
exception 'PHPExcel_Calculation_Exception' with message '粉丝数据!C2679 -> Formula Error: Operator '= ...
- Java读取Excel报错Unable to recognize OLE stream
Unable to recognize OLE stream 的解决方法 将xlsx用excel打开并另存为2003的xls,然后再运行即可解决问题 File file = new File(&quo ...
- java导出excel表格
java导出excel表格: 1.导入jar包 <dependency> <groupId>org.apache.poi</groupId> <artifac ...
- java导出excel报表
1.java导出excel报表: package cn.jcenterhome.util; import java.io.OutputStream;import java.util.List;impo ...
随机推荐
- CSS边距---盒子模型
CSS盒子模型 盒子模型主要是有margin(外边距).border(边框).padding(内边距).content(内容)组成,这些属性我们可以把它转移到我们日常生活中的盒子上来理解,日常生活中所 ...
- macaca运行报错之chrome-driver问题处理,关闭 Chrome 的自动更新
由于chrome浏览器自动更新,导致 macaca运行报错,重新安装和更新chrome-driver 之后,还需要把chrome浏览器降级到50版本: 但是chrome会自动更新,所以需要禁止.找到这 ...
- hosts代理
hosts代理文件:C:\Windows\System32\drivers\etc\HOSTS 内容如下: # Copyright (c) -, racaljk. # https://github.c ...
- implicit operator
class Digit { public Digit(double d) { val = d; } public double val; // ...other members // User-def ...
- 学习mongo系列(十一)关系
准备工作:首先在maxh数据库的address集合中先插入数据 > db.address.insert({child_address:"gansu"}) WriteResul ...
- object.assign()方法的使用
地址:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
- [hadoop] 一些基础概念
一.云的概念 1.云计算的概念 随时 随地 使用任何设备 获得任何服务 2.趋势 )资料开始回归集中处理(存储大量资料) 随时存取 降低遗失风险 减少传输成本 促进团队协作 )网页变为预设开发平台(网 ...
- Port Hacking
Port information21 ftp 主要看是否支持匿名,也可以跑弱口令22 ssh23 telnet79 Finger80 web 常见web漏洞以及是否为一些管理后台111 rpcinfo ...
- ijg库解码超大型jpeg图片
1. ijg库解码超大型jpeg图片(>100M)的时候,如何避免内存溢出. 采用边解码边压缩的策略,每次解码一行或者若干行图片数据,然后对于这些解码的数据,进行DQT(量化处理,过滤掉高频的数 ...
- CentOS7下ifconfig command not found
执行命令 yum install net-tools