java.lang.IllegalStateException: getOutputStream() has already been called for this response
来源:互联网 发布:众海消防主机编程密码 编辑:程序博客网 时间:2024/06/06 03:44
最近查看apache tomcat日志,发现经常出现一个错误如下:
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
网上查阅资料发现是response.getWriter()和response.getOutputStream()相冲突造成的,也就是getOutputStream()方法和getWriter()方法只能用一个。根据错误描述查看tomcat编译成的servlet文件时发现:在tomcat中把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();
- java.lang.IllegalStateException: getOutputStream() has already been called for this response,java.la
- 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完美解决方案
- struts2: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
- onvif学习5-视频点播实现
- const char*转char*
- Effective C++ 学记之13 以对象管理资源
- HDU 3549 Flow Problem
- hdu2199(方程求值二分法)
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- bio 与buffer_head 的区别和联系
- Android中AsyncTask的使用详解
- 动态管理视图和函数笔记-sql server 2005的一些动态函数
- 判断文件目录,并创建
- 覆写Button中的onClick函数时注意
- 和菜鸟一起学linux之本地git中心仓库建立
- JQuery验证 [注册]
- Nginx + PHP-FPM (11: Resource temporarily unavailable)