English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JSP Structure

The network server needs a JSP engine, which is a container to handle JSP pages. The container is responsible for intercepting requests for JSP pages. This tutorial uses Apache with an embedded JSP container to support JSP. Development.

The JSP container works in collaboration with the web server to provide the necessary runtime environment and other services for the normal operation of JSP and can correctly identify special elements exclusively belonging to JSP web pages.

The following diagram shows the position of the JSP container and JSP files in the web application.

JSP Processing

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

  • Just like any other ordinary 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 the disk and then converts them into Servlets. This conversion simply replaces all template text with 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 component of the web server will call the Servlet engine, then load and execute the Servlet class. During the execution, the Servlet generates HTML formatted output and embeds it in the HTTP response to be handed over to the web server.

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

  • Finally, the web browser processes the dynamically generated HTML web page in the HTTP response as if it were processing a static web page.

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

Under normal circumstances, the JSP engine will check if the Servlet corresponding to the JSP file already exists and whether the modification date of the JSP file is earlier than that of the Servlet. If the modification date of the JSP file is earlier than the corresponding Servlet, 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 compared to other scripting languages (such as PHP).

In general, JSP web pages are written in a way that is another way to write Servlets without becoming a Java programming expert. Apart from the explanation phase, JSP web pages can almost be treated as a regular Servlet.