JSP upload image generated Java.io.IOException:Stream closed exception resolution _JSP programming

Source: Internet
Author: User
Tags flush
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.