zoukankan      html  css  js  c++  java
  • 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);
    	}	
    }
    

    注:本人推荐使用第二种

  • 相关阅读:
    stl_hash_set.h
    stl_hash_map.h
    stl_algobase.h
    stl_relops.h
    stl_algo.h
    VC6常用插件
    visual assist(VA)设置快捷键(其它安装的插件设置快捷键也在这里)
    SVN常用命令说明
    Android 调用相册 拍照 实现系统控件缩放 切割图片
    Android 一个3D相册源码
  • 原文地址:https://www.cnblogs.com/chunyansong/p/5340291.html
Copyright © 2011-2022 走看看