Why jsp creates two links for PageContext and JspWriter while supporting Jsp for servlet

I created a basic Jsp example when I view a Servlet file automatically generated by Jsp. I saw two links to the PageContext and JspWriter methods in _jspService . Why there are two reflexes PageContext and JspWriter

public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException {

 final javax.servlet.jsp.PageContext pageContext; javax.servlet.http.HttpSession session = null; final javax.servlet.ServletContext application; final javax.servlet.ServletConfig config; javax.servlet.jsp.JspWriter out = null; final java.lang.Object page = this; javax.servlet.jsp.JspWriter _jspx_out = null; javax.servlet.jsp.PageContext _jspx_page_context = null; 

`

+6
source share
1 answer

This question is related to the implementation of the library of custom JSP tags and tag files. The non-final PageContext and JspWriter may change at run time. Here is a JSP example

 <html><body><%@ taglib uri="http://tomcat.apache.org/example-taglib" prefix="eg"%> <eg:log>It <%="TEST"%></eg:log></body></html> 

Tomcat 7 Generated Java Code

 1 pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); 2 _jspx_page_context = pageContext; 3 application = pageContext.getServletContext(); 4 config = pageContext.getServletConfig(); 5 session = pageContext.getSession(); 6 out = pageContext.getOut(); 7 _jspx_out = out; 8 out.write("<html><body>\r\n"); 9 // eg:log 10 examples.LogTag _jspx_th_eg_005flog_005f0 = (examples.LogTag) _005fjspx_005ftagPool_005feg_005flog.get(examples.LogTag.class); 11 _jspx_th_eg_005flog_005f0.setPageContext(_jspx_page_context); 12 _jspx_th_eg_005flog_005f0.setParent(null); 13 int _jspx_eval_eg_005flog_005f0 = _jspx_th_eg_005flog_005f0.doStartTag(); 14 if (_jspx_eval_eg_005flog_005f0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) { 15 if (_jspx_eval_eg_005flog_005f0 != javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE) { 16 out = _jspx_page_context.pushBody(); 17 _jspx_th_eg_005flog_005f0.setBodyContent((javax.servlet.jsp.tagext.BodyContent) out); 18 _jspx_th_eg_005flog_005f0.doInitBody(); 19 } 20 do { 21 out.write("It "); 22 out.print("TEST"); 23 int evalDoAfterBody = _jspx_th_eg_005flog_005f0.doAfterBody(); 24 if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN) 25 break; 26 } while (true); 27 if (_jspx_eval_eg_005flog_005f0 != javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE) { 28 out = _jspx_page_context.popBody(); 29 } 30 } 

On line 16, as soon as the program executes _jspx_page_context.pushBody() . The new JspWriter . It was used to capture body output, so data is not directly written to response outputStream . LogTag.doAfterBody() can receive the captured output and process it.

+1
source

All Articles