Java. io. IOException: Stream closed

Source: Internet
Author: User

When uploading images using jsp, you can directly change the java code to jsp. The following exception occurs during the upload: 8:59:21 org. apache. catalina. core. serious StandardWrapperValve invoke: Servlet. service () for servlet jsp threw exceptionjava. io. IOException: Stream closed... think twice about the code after turning jsp into servlet. As follows (very eye-catching ):...} catch (Exception e) {e. printStackTrace ();} finally {out. flush (); // out. close (); // This is the source code DBHelper. freeConnection (connection);} out. write ('\ R'); // As shown above, the out object is still in use, so the exception out as described at the beginning is generated. 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 to: 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. the method is pushBody (). 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 BodyContentextends JspWriterout built-in object

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.