No matter whether it is requetdispatcher. Forward or httpservletresponse. sendredirrect (), NO content can be actually output to the client before calling them !! If some content already exists in the buffer, the content will be cleared !!
Jspfracloud
_ Jspxfactory. releasepagecontext (_ jspx_page_context)
When multiple printwriter or jspwriter objects exist, the content is first output to the buffer zone! The content is output at the end of the JSP page !!
Call pagecontext. Forward () on the JSP page to redirect the page! Servlet
If you switch to HTML static files! This is because the default servlet is not generated by the printwriter object.
Serlet will call getservletoutputstream! Then return to the JSP page! Continue to complete the remaining page !! At this time, it is printed to the buffer! An error is reported! 1
If you do not want to report an error! You can only call response. getwriter on the JSP page to explicitly generate the printerwriter object !! In this way, the printwriter object will be used in the default servlet! Output page content !!
<%
Response. getwriter ();
Pagecontext. Forward ("test.html ");
%>
HTML pages are often cached! If this access is successful! The next page should fail! But the page is still correct! This is because of the cache results !!
If you switch to servlet, but the servlet opens the outputstream stream! An error is reported !! Conflict with the out of the JSP page !!
<%
Pagecontext. Forward ("Servlet/testforward ");
%>
Testforward Servlet
Public void doget (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception
{
Servletoutputstream SOS = response. getoutputstream ();
}
Check again
<Body>
1
<%
Printwriter PW = response. getwriter ();
PW. Print ("3 ");
%>
2
</Body>
Print 312
The compiled Servlet code is JspWriter out = null;
Relationship between JspWriter and PrintWriter !!
JspWriter inherits java. io. Writer
Similarly, PrintWriter is also its subclass !! That is, only the Writer subclass is used for jsp page output! Output the content to a buffer zone !!