java.lang.IllegalStateException: getOutputStream() has already been called for this response

警示:有bug应该仔细查看异常代码,里面说明了问题原因。

at org.apache.catalina.connector.Response.getWriter(Response.java:604)

at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)

ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception

从网上找了下资料,综合一下原因分析:

这是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”>

时间: 2024-10-02 07:47:26

java.lang.IllegalStateException: getOutputStream() has already been called for this response的相关文章

Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this respo

1.错误描述 Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response at org.apache.catalina.connector.Response.getWriter(Response.java:648) at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFa

java.lang.IllegalStateException: getWriter() has already been called for this response

java.lang.IllegalStateException: getWriter() has already been called for this response 出现原因: 1.代码中有打开的Response.getWriter(),未关闭 2.再次使用了ServletOutputStream out = response.getOutputStream(); 通过查看代码,response中的usingWriter=true,想办法将该标志位设置为false. response.r

使用printWrite 在jetty中报错 java.lang.IllegalStateException: STREAM

1 public void doFilter(ServletRequest request, ServletResponse response, 2 FilterChain chain) throws IOException, ServletException { 3 // TODO Auto-generated method stub 4 HttpServletRequest req=(HttpServletRequest)request; 5 HttpServletResponse res=

WARN::Committed before 500 Unable to show problem report:|java.lang.IllegalStateException

2015-01-06 18:23:17.160:WARN::Committed before 500 Unable to show problem report:|java.lang.IllegalStateException: STREAM||Class: org.mortbay.jetty.Response|File: Response.java|Method: getWriter|Line: 616 - org/mortbay/jetty/Response.java:616:-1 2015

批量下载的实现及java.lang.IllegalStateException异常

在工作流的一张表单里可能会有多个步骤上传附件,在用户的待办中往往会存在多条带有附件的任务,如果一一打开并且点击下载链接下载,不仅费时,而且繁琐,用户体验较差. OA系统采用的是FastDFS做为文件服务器,FastDFS的Java客户端提供了上传.下载等功能供调用. 在我之前的文章里对此有描述,目前已有的代码有对文件的批量上传功能,但下载的参数往往是针对单个文件.比如单个文件的下载方法如下: /**  * 文件下载  * @author chao.gao  * @date 2014-2-17 下

java.lang.IllegalStateException异常:简单的分析和简单解决方案

我们在做文件上传或者下载,或者过滤等操作时,可能要用到页面的输出流. 例如在action中使用: response.reset(); response.setContentType(”application/vnd.ms-excel”); OutputStream os = response.getOutputStream(); 抛出异常:java.lang.IllegalStateException 原因分析: 这是web容器生成的servlet代码中有out.write(””),这个和JSP

java.lang.IllegalStateException: Failed to load ApplicationContext

1.错误描述 INFO:2015-02-05 22:14:21[main] - Loading XML bean definitions from class path resource [applicationContext.xml] INFO:2015-02-05 22:14:22[main] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning INFO:2015-02-05

java.lang.IllegalStateException: ContainerBase.addChild: start

java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina] Tomcat部署Servlet时出错 caused by: Caused by: java.lang.IllegalArgumentException: Invalid <url-patt

开发中遇到的问题(一)——java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

1.错误描述: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 2.起因: 在Manifest中设置我的activity全屏 1 <activity android:name=".SplashActivity" 2 android:theme="@android:style/Theme.Black.No