解决getOutputStream() has already been called for this response

来源:互联网 发布:win32 界面编程 编辑:程序博客网 时间:2024/06/07 15:20

getOutputStream() has already been called for this response异常出现的原因和解决方法:

jsp中出现此错误一般都是在jsp中使用了输出流(如输出图片验证码,文件下载等),没有妥善处理好的原因。


jsp编译成servlet之后在函数

_jspService(HttpServletRequest request, HttpServletResponse response)的最后有一段这样的代码

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

这里是在释放在jsp中使用的对象,会调用response.getWriter(),因为这个方法是和response.getOutputStream()相冲突的!所以会出现以上这个异常。

解决:

加入两行:

out.clear();
out = pageContext.pushBody();

0 0