|
2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke
嚴(yán)重: Servlet.service() for servlet jsp threw exception
Java.io.IOException: Stream closed
...
百思不得其解,翻出 jsp 轉(zhuǎn)成 servlet 后的代碼。如下(很很的醒目一下):
復(fù)制代碼 代碼如下:
...
}catch(Exception e){
e.printStackTrace();
}finally{
out.flush(); //
out.close();// 此處為源始代碼
DBHelper.freeConnection(connection);
}
out.write('/r'); // 如上我已經(jīng)關(guān)了 out 對(duì)象,但此處還在使用,所以便產(chǎn)生了如開始所描述的異常
out.write('/n');
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (Java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
...
解決辦法:把程序中加紅加粗的代碼改成:
復(fù)制代碼 代碼如下:
out.flush() ;
out = pageContext.pushBody(); // 關(guān)于該段程序的解釋,doc中已經(jīng)說(shuō)的很清楚。
如下:(要特別注意一下flush()和clear()方法的區(qū)別,因?yàn)樾枨蟛煌绦蚴遣煌模?
abstract void | flush() Flush the stream. |
abstract void | clear() Clear the contents of the buffer. |
PageContext 實(shí)現(xiàn)了抽象類 JspContext ,方法:pushBody(), 保存當(dāng)前的out對(duì)象
BodyContent | pushBody() Return a new BodyContent object, save the current "out" JspWriter, and update the value of the "out" attribute in the page scope attribute namespace of the PageContext. |
public abstract class BodyContent
extends JspWriter
out 內(nèi)置對(duì)象
jsp技術(shù):JSP上傳圖片產(chǎn)生 java.io.IOException: Stream closed異常解決方法,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。