getOutputStream() has already been called for this response

1、情况1出现在JAVA类中

      背景:struts2下载Excel

      解决方案:在struts2中配置此下载的action时,不要return success了,要return 空就行了。

refurl:http://www.360doc.com/content/12/0612/13/1967709_217660151.shtml

 

2、情况2出现在JSP中

在输入图片时经常会报这样的错误,

原因就是在jsp生成的类中最后会执行如下语句:

finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }

即response会调用response.getWriter的,这会和getOutputStream冲突。

 

解决方案1:

 

在使用完输出流以后调用以下两行代码即可:
out.clear();
out = pageContext.pushBody();

 

缺点:当在页面出错重新跳回此JSP时,解决方案1会失效。

refurl:http://blog.csdn.net/iron_wang/article/details/4204672

 

解决方案2:

生成图片不要用JSP,用servlet生成才是完美解决方案。

refurl:http://wuzhengfei.iteye.com/blog/647754

 

 

 

 

你可能感兴趣的:(OutputStream)