jsp development of developing javaweb

    First, the initial jsp

    Front page in web development requires the use of html, css and js rendering the page displayed to the user, before we learned Servlet know if you want to output the contents of the front desk need to use the HttpServletResponse object to obtain the print stream and then output html tag line by line, which for developers is a nightmare. In view of this situation SUN company defined a technique for developing dynamic web resources that is jsp. JSP stands for Java Server Pages but its essence is the servlet user can directly write html code in jsp pages can also be nested java code jsp page. Jsp appear greatly improved the efficiency of people use java software development.

    Second, the operating principle of jsp

   jsp is the essence of Servlet. The browser sends a request to a server that is in its essence is tomcat Servlet access, because tomcat access to all the resources are used Servlet to achieve. When we first visit jsp, jsp files into the server will then be compiled into a servlet class file byte code and then execute. After jsp is translated into a java file inherits org.apache.jasper.runtime.HttpJspBase this class, but HttpJspBase inherited HttpServlet, so is the essence of jsp is a servlet. Because jsp the first time users need to be translated into accessible documents translated into java bytecode class files, so jsp page when the user first visits will be relatively slow, when a user when a second visit jsp page direct access to the class file so the speed will be faster access time than the first.

Source address: https: //upload-images.jianshu.io/upload_images/10077403-8d880f94e33ddbae.png imageMogr2 / auto-orient / strip | imageView2 / 2 / w / 425 / format / webp?

    Three, jsp built nine objects

    java file built nine objects in jsp, view jsp translation after that, these nine built-in objects are: request, response, session, application, out, pagecontext, config, page, exception. code show as below:

 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;


    try {
      response.setContentType("text/html; charset=utf-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
                  null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();

Wherein the request, response, session corresponding to the object is HttpServletRequest, HttpServletResponse, HttpSession objects, file application object is the ServletContext object, config object is the ServletConfig object, the pageContext object represents the context of the current page, you can get out JSP page, request, reponse by the object , session, application and other objects, page object represents the current jsp page itself.

Guess you like

Origin www.cnblogs.com/suyang-java/p/11511677.html