Java – why are we in JSP instead of system out. Write out in println() println()?

I started learning JSP. I saw that if we want to print something in JSP, we must write out Println () instead of system out. Pritnln (), but if we write system out. Pritnln () does not display any errors, but it does not o / P to the browser I wonder why? As we know, the system is a predefined class, and the output stream is the output stream connected to the console So why don't we write system. XML in JSP

Solution

Because we don't mean system Out, which is a variable that contains valid methods for JSP pages System. Out writes to the console of the servlet container (usually a log file); Out is a completely different class that writes the output stream of the generated response

When JSP becomes code, it (in theory, and Tomcat actually) goes through two steps: JSP – > servlet source code, and then servlet source code – > class The entire page is placed in a method where Tomcat looks like this:

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

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
        response.setContentType("text/html");
        pageContext = _jspxFactory.getPageContext(this,request,response,"qdforumerror.jsp",true,65536,true);
        _jspx_page_context = pageContext;
        application = pageContext.getServletContext();
        config = pageContext.getServletConfig();
        session = pageContext.getSession();
        out = pageContext.getOut();
        _jspx_out = out;

        /* =============================================
           ...your <% ... %> JSP code here,with
           any markup outside those tags converted into
           out.print("..."); statments...
           =============================================
        */
    }
    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 {
          _jspxFactory.releasePageContext(_jspx_page_context);
    }
}

As you can see, out is a variable in the method, and the type is jspwriter (instead of OutputStream, similar to system. Out)

(side note: the code contained in the <%!...% > tag, instead of the code in the normal <%...% > tag, will not be placed in the method; it will be placed in other places of the generated servlet class.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>