简单解决java.lang.IllegalStateException: getOutputStream() has already been called for this respons
2011-11-25 09:25
393 查看
网上的说明是这样的:
这个问题困扰了半天,在网上查阅了大量资料,基本上就是出自一两家之口.感觉说得也有道理response.getWriter()和response.getOutputStream()相冲突造成的.解决办法就 是:但我没在jsp用response,后来在javaeye上看到这样的解释:下载文件的时候报错!!! response这个对象是Servlet自己管理的,之所以出现上面的错误:
1.网上都说跟Output之类其他的输出流相互排斥了。
2.也可能是多次调用那个Struts里面定义的方法。
3.最后查出原因:Struts方法之间调用引起的。
因为:每个方法都返回的是一个ActionForward对象,而response是ActionForward对象参数,所以就会使response冲突! 分析得很有道理然后又在javaeye上看到一个网友说return null就ok了.然后我试了,对,没错了.这和上面网友的分析吻合.
以下是一个代码例子:
在实际的例子中,需要在最后返回null就可以的了。
这个问题困扰了半天,在网上查阅了大量资料,基本上就是出自一两家之口.感觉说得也有道理response.getWriter()和response.getOutputStream()相冲突造成的.解决办法就 是:但我没在jsp用response,后来在javaeye上看到这样的解释:下载文件的时候报错!!! response这个对象是Servlet自己管理的,之所以出现上面的错误:
1.网上都说跟Output之类其他的输出流相互排斥了。
2.也可能是多次调用那个Struts里面定义的方法。
3.最后查出原因:Struts方法之间调用引起的。
因为:每个方法都返回的是一个ActionForward对象,而response是ActionForward对象参数,所以就会使response冲突! 分析得很有道理然后又在javaeye上看到一个网友说return null就ok了.然后我试了,对,没错了.这和上面网友的分析吻合.
以下是一个代码例子:
result = StrUtil.getXmlStringFormJSON(json, this.getNewList(list,exter)); result = result.replaceAll("'", "\""); HttpServletResponse response = exter.getResponse(); response.flushBuffer(); ops = response.getOutputStream(); log.info("result111 is " + result); ops.write(result.getBytes("UTF-8")); ops.flush(); return null;
在实际的例子中,需要在最后返回null就可以的了。
相关文章推荐
- 简单解决java.lang.IllegalStateException: getOutputStream() has already been called for this
- 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
- 解决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实现文件下载,提示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: getWriter() 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: getWriter() 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
- 验证码异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: getWriter() has already been called for this response问题解决