Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JSP structure


May 12, 2021 JSP


Table of contents


JSP structure

The network server needs a JSP engine, which is a container to handle JSP pages. T he container is responsible for intercepting requests to JSP pages. T his tutorial supports JSP development using Apache with embedded JSP containers.

JSP containers work with Web servers to provide the necessary operating environment and other services for the proper operation of JSP, and to correctly identify special elements that are exclusive to JSP Web pages.

The following image shows where JSP containers and JSP files are in Web applications.

JSP structure


JSP processing

The following steps show how a Web server uses JSP to create Web pages:

  • Like other normal Web pages, your browser sends an HTTP request to the server.
  • The Web server recognizes that this is a request to a JSP Web page and passes the request to the JSP engine. This is done by using .jsp URL or a file.
  • The JSP engine loads JSP files from disk and converts them into servlets. This transformation simply converts 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 component of the Web server calls the servlet engine and loads and executes the servlet class. During execution, the servlet produces output in HTML format and is embedded in http response and handed over to the Web server.
  • The Web server returns HTTP response to your browser as a static HTML page.
  • Ultimately, web browsers handle HTML pages that are generated dynamically in HTTP response as if they were working on static web pages.

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

JSP structure

In general, the JSP engine checks that the servlet for the JSP file already exists and that the JSP file was modified before the servlet. I f the JSP file is modified earlier than the corresponding servlet, the container can determine that the JSP file has not been modified and that the servlet is valid. T his 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 a servlet without becoming a Java programming expert. I n addition to the interpretation phase, JSP pages can almost be treated as a normal servlet.