|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729255
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2009/2/1 5:50 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [轉貼]出現java.lang.IllegalStateException的幾種情況
- (轉)出現java.lang.IllegalStateException的幾種情況
原文連接:出現java.lang.IllegalStateException的幾種情況
出現java.lang.IllegalStateException的幾種情況
拋出異常:
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
綜合分析原因如下: 這是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();
就可以了; 我是在頁面輸出圖片之後寫的這兩句,代碼如下:
//輸出圖像到頁面
ImageIO.write(image, "JPEG", response.getOutputStream());
out.clear();
out = pageContext.pushBody();
2,不要在%〕〔%之間寫內容包括空格和換行符 3,在頁面寫入圖片的時候,需要flush()
OutputStream output=response.getOutputStream();
output.flush();
4,在頁面確定寫入
<meta http-equiv="Content-Type" content="text/html;charset=GB18030">
----------------------------------------------------------------------------------------------
在response.sendRedirect()時也可能會出現下列錯誤:
java.lang.IllegalStateException:
org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)
解決辦法如下: 在response.sendRedirect("");語句後面加上return語句就OK了。 例如:
response.sendRedirect("");
return ;
|
|
討論串
|