標籤:java.lang.illegalsta
警示:有bug應該仔細查看異常代碼,裡面說明了問題原因。
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)
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”>
java.lang.IllegalStateException: getOutputStream() has already been called for this response