java.lang.IllegalStateException: getOutputStream() has already been called for this response
2016-08-29 09:55
1351 查看
下载文件产生异常:
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;
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;
相关文章推荐
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response 分类: 异常
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解决方法及解释
- java.lang.IllegalStateException:getOutputStream() has already been called for this response的解决方法
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解决方案
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getOutputStream() has already been called for this response的解决办法
- java.lang.IllegalStateException: getOutputStream() has already been called for this response