异常:java.lang.IllegalStateException怎么解决?
2010-06-06 15:59
435 查看
抛出异常:
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();
就可以了;
2,不要在%〕〔%之间写内容包括空格和换行符
3,在页面写入图片的时候,需要flush()
OutputStream output=response.getOutputStream();
output.flush();
4,在页面确定写入<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312”>
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();
就可以了;
2,不要在%〕〔%之间写内容包括空格和换行符
3,在页面写入图片的时候,需要flush()
OutputStream output=response.getOutputStream();
output.flush();
4,在页面确定写入<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312”>
相关文章推荐
- 上传下载文件实例异常:java.lang.IllegalStateException怎么解决?
- 【JAVA秒会技术之异常解决】怎么解决eclipse报PermGen space异常的问题
- java连接Mysql遇到新问题!!!如下异常怎么解决?
- java.lang.OutOfMemoryError:Java head space 异常解决办法
- java.lang.reflect.MalformedParameterizedTypeException异常解决
- java.lang.OutOfMemoryError异常解决方法
- Android问题分享:DownloadManager基本用法及发生java.lang.SecurityException异常的解决办法
- java.lang.NoSuchMethodException异常解决
- MyEclipse 10 部署项目时报错,抛出java.lang.NullPointerException异常的解决方法
- java.lang.RuntimeException: Unable to instantiate activity ComponentInfo异常解决
- 【原创】java.lang.ClassCastException异常问题解决
- Java Web中调用Spark产生异常java.lang.NoSuchMethodError Jackson databind的解决办法
- 异常:java.lang.NoSuchFieldError: deferredExpression解决
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- Java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook异常的解决方法
- java.lang.IllegalStateException: Post too large异常及其解决办法
- java.lang.RuntimeException: Unable to instantiate activity ComponentInfo异常解决
- java.lang.RuntimeException: Unable to instantiate activity ComponentInfo异常解决
- 使用Spring实现异常统一处理【三】--java.lang.IllegalStateException: STREAM问题的解决
- android java.lang.IllegalArgumentException: The observer is null.异常解决