在做 jsp 上傳圖片時,把 java 代碼直接改成 jsp,上傳時產生 如下異常:
2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke
嚴重: Servlet.service() for servlet jsp threw exception
java.io.IOException: Stream closed
...
百思不得其解,翻出 jsp 轉成 servlet 后的代碼。如下(很很的醒目一下):
復制代碼 代碼如下:
...
}catch(Exception e){
e.printStackTrace();
}finally{
out.flush(); //
out.close();// 此處為源始代碼
DBHelper.freeConnection(connection);
}
out.write('/r'); // 如上我已經關了 out 對象,但此處還在使用,所以便產生了如開始所描述的異常
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);
}
...
復制代碼 代碼如下:
out.flush() ;
out = pageContext.pushBody(); // 關于該段程序的解釋,doc中已經說的很清楚。
abstract voidflush()
Flush the stream.
abstract voidclear()
Clear the contents of the buffer.
BodyContentpushBody()
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.
|
新聞熱點
疑難解答