出现java.lang.IllegalStateException的几种情况
来源:互联网 发布:双向数据绑定原理 编辑:程序博客网 时间:2024/05/29 18:04
抛出异常:
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
综合分析原因如下:
这是web容器生成的servlet代码中有out.write(””),这个和JSP中调用的response.getOutputStream()产生冲突.
即Servlet规范说明,不能既调用 response.getOutputStream(),又调用response.getWriter(),无论先调用哪一个,在调用第二个时候应会抛出 IllegalStateException,因为在jsp中,out变量是通过response.getWriter得到的,在程序中既用了response.getOutputStream,又用了out变量,故出现以上错误。
解决方案:
1.在程序中添加:
out.clear();
out = pageContext.pushBody();
就可以了;
我是在页面输出图片之后写的这两句,代码如下:
//输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());
out.clear();
out = pageContext.pushBody();
2,不要在%][%之间写内容包括空格和换行符
3,在页面写入图片的时候,需要flush()
OutputStream output=response.getOutputStream();
output.flush();
4,在页面确定写入<meta http-equiv="Content-Type" content="text/html;charset=GB18030">
----------------------------------------------------------------------------------------------
在response.sendRedirect()时也可能会出现下列错误:
java.lang.IllegalStateException:
解决办法如下:
在response.sendRedirect("");语句后面加上return语句就OK了。
例如:response.sendRedirect("");
- 出现java.lang.IllegalStateException的几种情况
- 出现java.lang.IllegalStateException的几种情况
- 出现java.lang.IllegalStateException的几种情况
- spring出现java.lang.IllegalStateException异常的几种可能
- Fragment使用时出现 java.lang.IllegalStateException
- sbt编译出现(*:ssExtractDependencies) java.lang.IllegalStateException
- 使用okhttp3出现java.lang.IllegalStateException: closed
- Android的java.lang.IllegalStateException
- java异常,java.lang.IllegalStateException,在进行JasperReports导出报表的时候出现的异常
- 关于Java空指针异常的几种情况的总结(java.lang.NullPointerException)
- 出现 undefined 的几种情况
- 举例说明android中出现java.lang.IllegalStateException: database not open这种错误的原因及解决办法
- Struts2下载文件点取消出现的异常java.lang.IllegalStateException 解决方案
- 解决struts/spring偶尔出现java.lang.IllegalStateException: Cannot call sendRedirect() after the response的问题
- Fragment中使用出现的java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
- 正则表达式出现的一个错误java.lang.IllegalStateException: No successful match so far
- java.lang.IllegalStateException异常的问题
- java.lang.IllegalStateException: STREAM错误的理解
- SilverLight 2 初体验
- VB 关闭其它窗口
- 批量读取文件
- MyEclipse6快捷键
- T-Sql 学习(12) - 集合处理
- 出现java.lang.IllegalStateException的几种情况
- 压缩ViewState
- Windows SDK编程之建立控件
- hadoop应用之安装篇
- XML 常见问题
- 【存档】msdn里关于字符串转换的一段
- 阿郎笔试题
- CAN
- .net正则过滤html