关闭

java.lang.IllegalStateException: getOutputStream() has already been called for this response

标签: exception
211人阅读 评论(0) 收藏 举报
分类:

下载文件产生异常:

java.lang.IllegalStateException: getOutputStream() has already been called for this response


response.getWriter()和response.getOutputStream()相冲突造成的

// 通过response的输出流把工作薄的流发送浏览器形成文件
		OutputStream outStream=null;
		try{
			outStream = response.getOutputStream();
			workBook.write(outStream);
			outStream.flush();	
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(outStream!=null){
				outStream.close();
			}
			if(workBook!=null){
				workBook.close();
			}
		}

在Controller层返回null,切记一定要返回null!有些人总觉得是流未关闭,关闭流之后依旧抛出该异常



	public ModelAndView excelParse(@RequestParam(value="excelFile",required=false) MultipartFile file,
							HttpServletRequest request,HttpServletResponse response) throws Exception{
		ModelAndView view=new ModelAndView("ownerinfo/owner_import");	
<span style="white-space:pre">		</span>ownerImportService.ownerImport(is,response,request);
	<span style="white-space:pre">	</span>return null;



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:135309次
    • 积分:2587
    • 等级:
    • 排名:第14238名
    • 原创:105篇
    • 转载:127篇
    • 译文:1篇
    • 评论:9条
    最新评论