JSP structure
The web server needs a JSP engine, which is a container to process JSP pages. The container is responsible for intercepting requests for JSP pages. This tutorial uses Apache with a built-in JSP container to support JSP development.
The JSP container cooperates with the Web server to provide the necessary operating environment and other services for the normal operation of JSP, and can correctly identify special elements unique to JSP web pages.
The following figure shows the location of the JSP container and JSP files in the Web application.
JSP processing
The following steps show how a web server uses JSP to create a web page:
-
Just like any other normal web page, your browser sends an HTTP request to the server.
The Web server recognizes that this is a request for a JSP web page and passes the request to the JSP engine. This is done using a URL or a .jsp file.
The JSP engine loads JSP files from disk and converts them into servlets. This transformation simply converts all template text into 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, and then load and execute the servlet class. During execution, the servlet generates output in HTML format 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 web page.
Ultimately, the web browser processes the dynamically generated HTML web pages in the HTTP response as if it were a static web page.
The steps mentioned above can be represented by the following figure:
Under normal circumstances, the JSP engine will check whether the servlet corresponding to the JSP file already exists. , and check 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 be sure 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 are another way to write servlets without becoming a Java programming expert. Except for the interpretation phase, a JSP web page can be treated almost as an ordinary servlet.