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

【转】http://sxgxy2008.blog.163.com/blog/static/76255270201021164613946/

在使用struts2 +hibernate+spring 框架的项目中,用到下载,在下载时后台爆出下列异常:

严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:604)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:178)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)
at org.apache.jsp.success_jsp._jspService(success_jsp.java:132)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)
at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:127)
at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:78)
at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:51)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)

网上查了一下资料,情况如下,

这个问题困扰了半天,在网上查阅了大量资料,基本上就是出自一两家之口.感觉说得也有道理response.getWriter()和response.getOutputStream()相冲突造成的.但我没在jsp用response,

response这个对象是Servlet自己管理的,之所以出现上面的错误:
1.网上都说跟Output之类其他的输出流相互排斥了。
2.也可能是多次调用那个Struts里面定义的方法。
3.最后查出原因:Struts方法之间调用引起的。
因为:每个方法都返回的是一个ActionForward对象,而response是ActionForward对象参数,所以就会使response冲突!
分析得很有道理然后又在javaeye上看到一个网友说return null就ok了.然后我试了,对,没错了.这和上面网友的分析吻合.

 

这个问题算告一段落了.感谢网友提供的帮助支持哈!

你可能感兴趣的:(java,apache,jsp,struts,servlet)