Java. io. IOException: Stream closed exception

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:
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

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.