JSP Structure
A web server needs a JSP engine, that is, a container, to process 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 together with the Web server to provide the necessary runtime environment and other services for JSP to run properly, and it can correctly identify the special elements that belong to JSP pages.
The figure below shows where the JSP container and JSP files are located in a Web application.

JSP Processing
The following steps show how a Web server uses JSP to create web pages:
-
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 page and passes the request to the JSP engine. This is done through the use of a URL or a .jsp file.
-
The JSP engine loads the JSP files from disk and 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 invoke the Servlet engine, then load and execute the Servlet class. During execution, the Servlet produces output in HTML format and embeds it in the HTTP response to be handed back to the Web server.
-
The Web server returns the HTTP response to your browser in the form of a static HTML page.
-
Finally, the Web browser processes the dynamically generated HTML page in the HTTP response just as it would a static page.
The steps mentioned above can be represented by the following figure:
In general, the JSP engine checks whether the Servlet corresponding to the JSP file already exists and whether the JSP file's modification date is earlier than the Servlet's. If the JSP file's modification date 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 whole process more efficient and faster compared with other scripting languages (such as PHP).
In summary, JSP pages are just another way to write Servlets without having to become a Java programming expert. Apart from the interpretation phase, a JSP page can be treated almost as an ordinary Servlet.