对于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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. easyPOI导出excel报错

    http-nio--exec- at :: - excel cell export error ,data is :com.jn.ssr.superrescue.web.qc.dto.Automati ...

  4. asp.net 发布后,遇到的导出excel报错的问题

    做的asp.net程序,最近要发布在外网上,发布过程不太难,网上都有现成的,只要按照相应的步骤基本都不会有什么问题,关键是发布成功后,程序中涉及到excel的导出或者导入问题,就会提示“检索COM 类 ...

  5. 导出excel报错

    System.ComponentModel.Win32Exception: 拒绝访问 1.问题现象: foreach (System.Diagnostics.Process thispro in Sy ...

  6. php 导出 Excel 报错 exception 'PHPExcel_Calculation_Exception' with message

    exception 'PHPExcel_Calculation_Exception' with message '粉丝数据!C2679 -> Formula Error: Operator '= ...

  7. Java读取Excel报错Unable to recognize OLE stream

    Unable to recognize OLE stream 的解决方法 将xlsx用excel打开并另存为2003的xls,然后再运行即可解决问题 File file = new File(&quo ...

  8. java导出excel表格

    java导出excel表格: 1.导入jar包 <dependency> <groupId>org.apache.poi</groupId> <artifac ...

  9. java导出excel报表

    1.java导出excel报表: package cn.jcenterhome.util; import java.io.OutputStream;import java.util.List;impo ...

随机推荐

  1. Codeforces Round #383 (Div. 2) A,B,C,D 循环节,标记,暴力,并查集+分组背包

    A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 ...

  2. 背景:表A数据误操作,被delete了,恢复。

    SELECT MAX(Scn) FROM Sys.Smon_Scn_Time WHERE Time_Dp < TO_DATE('2015-09-18', 'YYYY/MM/DD') select ...

  3. WebSocket实战之————Workerman服务器的安装启动

    安装php apt-get install php5-cli root@iZ23b64pe35Z:/home/www# php -v PHP 5.5.9-1ubuntu4.20 (cli) (buil ...

  4. timer控件、三级联动

    timer控件: 实现时间日期自增长: using System; using System.Collections.Generic; using System.ComponentModel; usi ...

  5. http://www.oreilly.com/catalog/errataunconfirmed.csp?isbn=9780596529321

    集体智慧勘误表: http://www.oreilly.com/catalog/errataunconfirmed.csp?isbn=9780596529321 ------------------- ...

  6. Spring中@Async注解实现“方法”的异步调用

    原文:http://www.cnblogs.com/zhengbin/p/6104502.html 简单介绍: Spring为任务调度与异步方法执行提供了注解支持.通过在方法上设置@Async注解,可 ...

  7. 张艾迪(创始人):Hello.世界...

    The World No.1 Girl :Eidyzhang The World No.1 Internet Girl :Eidyzhang AOOOiA.global Founder :Eidyzh ...

  8. json 转换错误:JSON.parse expected property name or '}'

    错误原因: 格式要为: [ { "name":"张三", "age":"20" }, { "name" ...

  9. 读javascript高级程序设计15-Ajax,CORS,JSONP,Img Ping

    平时用惯了jQuery.ajax之类的方法,却时常忽略了它背后的实现,本文是学习了AJAX基础及几种跨域解决方案之后的一些收获. 一.AJAX——XMLHttpRequest 谈起Ajax我们都很熟悉 ...

  10. ionic本质

    ionic本质一开发工具,ionic项目目录里在大堆东西,一堆插件(plugins),还有一堆npm包(node_modules),其实都是骗人的-( ̄▽ ̄-)~ 什么nodejs,npm只是为了解决 ...