Jsp Architecture
# JSP Structure
A web server needs a JSP engine, also known as 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 in conjunction with the web server to provide the necessary runtime environment and other services for the proper functioning of JSP, and can correctly identify special elements exclusive to JSP pages.
The following diagram shows the position of the JSP container and JSP files in a web application.
!(#)
* * *
## JSP Processing
The following steps show how a web server uses JSP to create web pages:
* Just like any other regular 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 using the URL or the .jsp file.
* The JSP engine loads the JSP file from disk and converts it into a Servlet. This conversion is simply a matter of replacing all template text with println() statements and converting 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 HTML-formatted output and embeds it within an HTTP response, which is then passed to the web server.
* The web server returns the HTTP response to your browser in the form of a static HTML web page.
* Finally, the web browser processes the dynamically generated HTML page in the HTTP response as if it were a static web page.
The steps mentioned above can be represented by the following diagram:
!(#)
Generally, the JSP engine checks if the Servlet corresponding to the JSP file already exists and checks if 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 (like PHP).
In summary, JSP pages are just another way to write Servlets without becoming a Java programming expert. Except for the interpretation phase, JSP pages can be treated almost like ordinary Servlets.
YouTip