jsp丟出java.lang.IllegalStateException: getOutputStream()錯誤


我在一張圖片輸出的網頁
有時執行會丟出
java.lang.IllegalStateException: getOutputStream() has already been called for this response
後來查一下Google原來在response.getOutputStream()的前面也就是
ChartUtilities.writeChartAsJPEG(response.getOutputStream(),jfc,580,250);

在寫兩行程式
out.clear();
out = pageContext.pushBody();                

按照參考網站的說明是說

=============================================================================
產生這樣的異常原因:是servlet代碼中有out.write(""),
這個和JSP中調用的 response.getOutputStream()產生衝突.即Servlet規範說明,
不能既調用 response.getOutputStream(),又調用response.getWriter(),無論先調用哪一個,在
調用第二個時候應會拋出 IllegalStateException,因為在jsp中,out變數實際上是通過response.getWriter得到的,
程式中既用了 response.getOutputStream,又用了out變數,故出現以上錯誤。
===============================================================================
arrow
arrow
    全站熱搜

    ROACH 發表在 痞客邦 留言(0) 人氣()