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

来源:互联网 发布:同志交友软件排行 编辑:程序博客网 时间:2024/04/29 11:05

下载文件产生异常:

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
原创粉丝点击