Nested servlet requests cause stream closed exceptions

Source: Internet
Author: User

Note:<JSP: Include page = "A. jsp"> tag: only one entity page can be nested, and one Servlet request cannot be nested.If a Servlet request is nested, the error stream closed may be reported in the background.

 

If the tag references a Servlet request, such as <JSP: Include page = "Aaction. do? Method = test "/>:

java.io.IOException: Stream closedat org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:173)at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:956)at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:621)..

 

This is because the JSP has closed the stream when submitting the first request. This error occurs when the request is sent again.

 

If the flush = "true" attribute is specified in the <JSP: Include> label, the following error is returned: Java. lang. illegalstateexception: response already committed. Similarly, when flush = "true" is specified, this exception is thrown when the jspwriter object executes the flush cache instead of the same response object.

 

If the page needs to include a Servlet request, you can use<C: Import src = "aaciton. do? Method = test "/>Replace.

 

Note: When I encountered this problem in my project, I checked the converted Java file source code corresponding to the JSP page under Tomcat work and found that an exception was thrown when the include request was executed, in a catch exception, this exception is thrown when necessary operations are performed on the out stream. When debugging the code, it is found that when jspruntimelibrary executes the include method, the value of the closed parameter in the input parameter out is true, and an exception is thrown. It is hard to understand why closed = true in the out object is started, the attribute value of closed is changed from false to true only when the out clause closes the stream. In Baidu, most of the problems are described and partially unclear answers. Taking into account the problem is easy to appear, and the answer is not easy to search, close up this article to prevent similar errors.

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.