在做 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.
新闻热点
疑难解答