In doing JSP upload pictures, the Java code directly into the JSP, upload the following exception:
2012-12-31 8:59:21 Org.apache.catalina.core.StandardWrapperValve Invoke
Serious: Servlet.service () for Servlet JSP threw exception
Java.io.IOException:Stream closed
...
Baffled, turn the JSP into a servlet after the code. The following (very eye-catching):
Copy Code code as follows:
...
}catch (Exception e) {
E.printstacktrace ();
}finally{
Out.flush (); //
Out.close ()//Here is the source start code
Dbhelper.freeconnection (connection);
}
Out.write (' \ R '); As I've closed the out object, I'm still using it here, so I have the exception that I 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);
}
...
Workaround: Add red and bold code to the program:
Copy Code code as follows:
Out.flush ();
out = Pagecontext.pushbody (); As for the explanation of the procedure, DOC has made it very clear.
as follows: (Pay special attention to the difference between the flush () and the clear () method because the requirements are different for different programs)
abstract void |
flush() Flush the stream. |
abstract void |
clear() Clear the contents of the buffer. |
PageContext implements the abstract class Jspcontext method: Pushbody (), saving 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 objects