下载文件时报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this respons
2012-08-14 18:03
573 查看
此文档参照网络整理
异常信息:
java.lang.IllegalStateException: getOutputStream() has already been called for thisresponse
产生环境:
Tomcat 5.0 + jdk 1.4
原因分析:
在tomcat下jsp中出现此错误一般都是在jsp中使用了输出流(如输出图片验证码,文件下载等),但没有妥善处理好数据流。
具体原因就是:
在tomcat中jsp编译成servlet之后在函数_jspService(HttpServletRequestrequest, HttpServletResponse response)的最后有一段这样的代码
finally{
if (_jspxFactory !=null)
jspxFactory.releasePageContext(_jspx_page_context);
}
这里是在释放在jsp中使用的对象,会调用response.getWriter(),因为这个方法是和response.getOutputStream()相冲突的!所以会出现以上这个异常。
然后当然是要提出解决的办法,其实挺简单的(并不是和某些朋友说的那样--将jsp内的所有空格和回车符号所有都删除掉),在使用完输出流以后调用以下两行代码即可:
out.clear();
out = pageContext.pushBody();
异常信息:
java.lang.IllegalStateException: getOutputStream() has already been called for thisresponse
产生环境:
Tomcat 5.0 + jdk 1.4
原因分析:
在tomcat下jsp中出现此错误一般都是在jsp中使用了输出流(如输出图片验证码,文件下载等),但没有妥善处理好数据流。
具体原因就是:
在tomcat中jsp编译成servlet之后在函数_jspService(HttpServletRequestrequest, HttpServletResponse response)的最后有一段这样的代码
finally{
if (_jspxFactory !=null)
jspxFactory.releasePageContext(_jspx_page_context);
}
这里是在释放在jsp中使用的对象,会调用response.getWriter(),因为这个方法是和response.getOutputStream()相冲突的!所以会出现以上这个异常。
然后当然是要提出解决的办法,其实挺简单的(并不是和某些朋友说的那样--将jsp内的所有空格和回车符号所有都删除掉),在使用完输出流以后调用以下两行代码即可:
out.clear();
out = pageContext.pushBody();
相关文章推荐
- 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response
- 文件下载:java.lang.IllegalStateException: getOutputStream() has already been called for this response
- 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this re
- 文件能下载,但是报错: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 respons
- java.lang.IllegalStateException: getOutputStream() has already been called for this response 分类: 异常
- java.lang.IllegalStateException: getOutputStream() has already been called for this respons解决办法
- SSH中发生异常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: getInputStream() has already been called for this request该异常的解决方法!
- Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this respo
- 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
- 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
- JSP文件下载及出现getOutputStream() has already been called for this response的解决方法
- java.lang.IllegalStateException: getOutputStream() has already been called for this response