Solution to stream closed exception generated by JSP uploading pictures


When uploading pictures by JSP, the Java code is directly changed to JSP, and the following exception occurs when uploading:
2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke
Serious: servlet. Service() for servlet JSP threw exception Stream closed

I couldn’t figure it out. I turned JSP into servlet code. The following is very striking:

Copy codeThe code is as follows:

}catch(Exception e){
out.flush(); //
out.close();// Here is the source code
out.write(‘\r’); // As mentioned above, I have closed the out object, but it is still used here, so the exception described at the beginning is generated
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch ( e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
} finally {

Solution: change the red and bold code in the program to:

Copy codeThe code is as follows:
out.flush() ;
out = pageContext.pushBody(); // As for the explanation of this procedure, Doc has made it very clear.

As follows: (pay special attention to the difference between the flush () and clear () methods, because different programs have different requirements.)

abstract void flush()
Flush the stream.
abstract void clear()
Clear the contents of the buffer.

Pagecontext implements the abstract class jspcontext, method: 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 BodyContent
extends JspWriter

Out built in objects

Recommended Today

How to use XML format data processing library rexml in Ruby

Use re as a treeXML REXMLThe purpose is just enough. To the greatest extent, it can complete the task well. In fact, rexml supports two different styles of XML processing – “tree” and “stream”. The first style is the simpler version that DOM is trying to do; The second style is the simpler version Sax […]