JSP upload images to generate java. io. IOException: Stream closed exception resolution

  • 2020-06-03 08:02:53
  • OfStack

When uploading images from jsp, change the java code directly to jsp, and the following exceptions occur:
2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke
Severe: Servlet. () for servlet threw exception
java.io.IOException: Stream closed
Scratching their heads, jsp to servlet after the code. The following (very striking 1 below) :
}catch(Exception e){ 
out.flush(); // 
out.close();//  Here is the source-beginning code  
out.write('\r'); //  As above I have already closed  out  Object, but still in use here, so as to produce the exception described at the beginning  
} 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 { 

Solution: Change the program's bold and red code to:
out.flush() ; 
out = pageContext.pushBody(); //  An explanation of the procedure ,doc That's pretty clear.  

Here's how :(pay special attention to the differences between flush() and clear() methods under 1, 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 with the 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 articles: