JSP learning (two) -----JSP structure

One, JSP structure

The web server needs a JSP engine (JSP container, which is part of the web server. It is used to provide network services on top of the sent requests and responses, decode MIME-based requests, and format MIME-based responses. Commonly used tomcat, jboss, weblogic is a Servlet container). That is, a container to process JSP pages. The container is responsible for intercepting requests for JSP pages. Its life cycle is managed by the container, and the servlet life cycle is represented by the init(), service(), and destroy() methods in the java.servlet.Servlet interface. The life cycle of a servlet has four stages: loading and instantiation, initialization, request processing, and destruction.

Its life cycle is managed by the container. The life cycle of a servlet is represented by the init(), service(), and destroy() methods in the java.servlet.Servlet interface. The life cycle of a servlet has four stages: loading and instantiation, initialization, request processing, and destruction.

                                  

Two, JSP processing

The following steps show how the web server uses JSP to create web pages:

  • Just like other ordinary web pages, your browser sends an HTTP request to the server.

  • The Web server recognizes that this is a request for a JSP page, and passes the request to the JSP engine. This is done by using URL or .jsp file.

  • The JSP engine loads JSP files from the disk, and then converts them into servlets. This conversion simply changes all template text to println() statements, and converts all JSP elements into Java code.

  • The JSP engine compiles the servlet into an executable class and passes the original request to the servlet engine.

  • A certain component of the Web server will call the Servlet engine, then load and execute the Servlet class. During the execution process, the Servlet generates HTML format output and embeds it in the HTTP response and submits it to the Web server.

  • The web server returns the HTTP response to your browser in the form of a static HTML page.

  • In the end, the web browser processes the dynamically generated HTML pages in the HTTP response as if it were processing static web pages.

The steps mentioned above can be represented by the following figure:

                               ​​​

 

Under normal circumstances, the JSP engine checks whether the servlet corresponding to the JSP file already exists, and checks whether the modification date of the JSP file is earlier than the servlet. If the modification date of the JSP file is earlier than the corresponding servlet, then the container can determine that the JSP file has not been modified and the servlet is valid. This makes the entire process more efficient and faster than other scripting languages ​​(such as PHP).

In general, JSP web pages use another way to write Servlet without becoming a Java programming master. Except for the interpretation stage, JSP web pages can almost be treated as an ordinary Servlet.

 

 

 

Guess you like

Origin blog.csdn.net/qq_36171263/article/details/85057588
jsp