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 ...
随机推荐
- javascript 去掉空格之后的字符 正则表达式
从后端数据库读取时间时,经常会把整个日期年月日包括时分秒都取到,如2015-1-28 14:56:00,但是一般的我们只需要前面的年月日就行了.一个简单的方法,直接用split(" &quo ...
- AlarmManager 实现闹钟的基本功能
先上效果图 这是一个利用AlarmManager做的最简单的闹钟!迟点再把重复响铃(例如星期一,星期三,重复响铃) 1.MainActivity package com.example.domeref ...
- HTTP中的摘要认证机制
引子: 指定和服务器端交互的HTTP方法,URL地址,即其他请求信息: Method:表示http请求方法,一般使用"GET","POST". url:表示请求 ...
- mac 安装 Scrapy
一.pip安装Scrapy 运行命令 sudo pip install Scrapy(不带sudo 可能会出现 Permission denied) 然后 pip freeze 查看已经有 scrap ...
- 程序设计入门—Java语言 第五周编程题 2井字棋(5分)
2 井字棋(5分) 题目内容: 嗯,就是视频里说的那个井字棋.视频里说了它的基本思路,现在,需要你把它全部实现出来啦. 你的程序先要读入一个整数n,范围是[3,100],这表示井字棋棋盘的边长.比如n ...
- http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keyword
Observe that you call obj.draw as : <button onclick="obj.draw() The first time obj.draw is c ...
- spring aop搭建redis缓存
SpringAOP与Redis搭建缓存 近期项目查询数据库太慢,持久层也没有开启二级缓存,现希望采用Redis作为缓存.为了不改写原来代码,在此采用AOP+Redis实现. 目前由于项目需要,只需要做 ...
- 20161026__Oracle10g_DataGuard
1. orcl.__db_cache_size=180355072 orcl.__java_pool_size=4194304 orcl.__large_pool_size=4194304 orcl. ...
- spark standalone模式单节点启动多个executor
以前为了在一台机器上启动多个executor都是通过instance多个worker来实现的,因为standalone模式默认在一台worker上启动一个executor,造成了很大的不便利,并且会造 ...
- Java Web基础:JSP基础概念
JSP介绍 JSP全称是Java Server Pages,它和Servlet都是Sun公司定义的用于开发动态Web资源的技术,它解决了Servlet输出流排版复杂和难以维护的问题.JSP完美融合了H ...