java.lang.IllegalStateException: getOutputStream() has already been called 解决办法

来源:互联网 发布:阿里云国际版注册攻略 编辑:程序博客网 时间:2024/05/21 08:37

今天上班做从数据库查询图片到jsp页面显示,结果报java.lang.IllegalStateException: getOutputStream() has already been called 错误,折腾了将近半天的时间才弄出来。

在网上查阅了很多资料基本上都是一家之言,虽然说得都对,不过没有源码。所以我写下来供大家查阅。废话不多说,直接贴代码:


1、jsp页面(注:我用的是springMVC)

<img style="margin-top: 100px;" alt="投诉举报流程图" src="${stream }">


2、后台java Action方法:

/**
* 投诉举报流程图

* @author wangmingyuan
* @return ModelAndView
* @serialData 2016年11月24日下午4:16:05
*/
@RequestMapping(value = "/complaintreportpicture")
public ModelAndView complaintreportpicture(String proId,HttpServletRequest request,HttpServletResponse response,Model model) {
Map<String, Object> vdata = new HashMap<String, Object>();
InputStream stream =  wfComplaintReportService.findProcessPic("1");

try {
OutputStream output=response.getOutputStream();
int len=-1;  
            byte[]buf=new byte[1024];  
            while((len=stream.read(buf,0,1024))!=-1){  
            output.write(buf,0,len); 
            }
            model.addAttribute("stream",stream);
            output.flush();
            return null;  
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  
return super.load("workflow/complaintreport/complaint_picture", vdata);
}



以上经过测试没问题!!


1 0
原创粉丝点击