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 ...
随机推荐
- ConsensusClusterPlus根据基因表达量对样品进行分类
#http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2881355/ 一致聚类方法,采用重抽样方法来验证聚类合理性. library(ALL)data(ALL)d ...
- java高薪之路__010_设计模式
设计模式只是一个在构建大型工程时,为了方便更改,添加,查询和管理的一种代码工具,没有必要单独为了设计模式而使用设计模式,使简单的事情复杂化. 总体来说设计模式分为三大类: 1. 创建型模式,共五种 - ...
- 关于php语言的使用! ------php语言与JavaScript的使用 方法是相似
<script type="text/javascript"> </script>--js与PHP同是一种弱类型语言 弱类型语言只是不显示表现 定义变量时 ...
- javascript事件之:谈谈自定义事件
对于JavaScript自定义事件,印象最深刻的是用jQuery在做图片懒加载的时候.给需要懒加载的图片定义一个appear事件.当页面图片开始出现时候,触发这个自定义的appear事件(注意,这里只 ...
- Spring Boot Admin的使用
http://www.jianshu.com/p/e20a5f42a395 ******************************* 上一篇文章中了解了Spring Boot提供的监控接口,例如 ...
- 横向滑动的HorizontalListView滑动指定位置的解决方法
项目中用到了自定义横向滑动的控件:HorizontalListView,点击其中一项,跳转到另外一个大图界面,大图界面也是HorizontalListView,想使用setSelection方法设定 ...
- Debian添加raw裸设备
一.检查系统是否已经启用了raw模块 root@frog:~# lsmod|grep raw 如果系统没有启用raw模块! 二. 设置系统自动启用raw root@frog:~# echo raw & ...
- LRU Cache [LeetCode]
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- 安装mongodb
安装mongodb的时候遇到一些麻烦 首先将安装包下下来 安装的是windows版本的 将bin文件夹加入环境变量后通过mongod和mongo指令就可以进行操作,很方便 用指令mongod --db ...
- 转---- javascript prototype介绍的文章
JavaScript是基于对象的,任何元素都可以看成对象.然而,类型和对象是不同的.本文中,我们除了讨论类型和对象的一些特点之外,更重要的是研究如何写出好的并且利于重用的类型.毕竟,JavaScrip ...