When uploading images using jsp, you can directly change the java code to jsp. The following exception occurs during the upload:
2012-12-31 8:59:21 org. apache. catalina. core. StandardWrapperValve invoke
Severe: Servlet. service () for servlet jsp threw exception
Java. io. IOException: Stream closed
...
Think twice about the code after turning jsp into servlet. As follows (very eye-catching ):
Copy codeThe Code is as follows :...
} Catch (Exception e ){
E. printStackTrace ();
} Finally {
Out. flush ();//
Out. close (); // the source code is used here.
DBHelper. freeConnection (connection );
}
Out. write ('\ R'); // as above, I have disabled the out object, but it is still in use, so an exception is generated as described at the beginning.
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 );
}
...
Solution: change the code in red and bold in the program:Copy codeThe Code is as follows: out. flush ();
Out = pageContext. pushBody (); // the description of this program is clearly stated in the doc.
(Note the differences between the flush () and clear () methods, because different programs are required)
abstract void |
flush() Flush the stream. |
abstract void |
clear() Clear the contents of the buffer. |
PageContext implements the abstract class JspContext by pushBody () to save the current out object.
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 built-in object