java.lang.IllegalStateException: getOutputStream() has already been called for this response解決方案

Ruthless發表於2013-06-21

異常產生原因:web容器生成的servlet程式碼中有out.write(""),這個和JSP中呼叫的response.getOutputStream()產生衝突.即Servlet規範說明,不能既呼叫response.getOutputStream(),又呼叫response.getWriter(),無論先呼叫哪一個,在呼叫第二個時候應會丟擲IllegalStateException,因為在jsp中,out變數實際上是透過response.getWriter得到的,你的程式中既用了 response.getOutputStream,又用了out變數,故出現以上錯誤。

1、Jsp解決辦法,在程式的最後新增:

out.clear();
out = pageContext.pushBody();

2、Struts2解決辦法
直接讓action中的處理方法返回null,問題就解決啦!!!

相關文章