Latest web development tutorials

JSP structure

Web server will need a JSP engine, which is a container for the JSP page. Container is responsible for intercepting requests for JSP pages. This tutorial uses an embedded Apache JSP container to support the development of JSP.

JSP container and the Web server collaboration, to provide the necessary operating environment and other services for the JSP normal operation and can correctly identify the particular element specific to JSP pages.

The following figure shows the JSP container and JSP files in the Web application in which position.


JSP Processing

The following steps show how to use the Web server to create a JSP page:

  • Like other common web page as your browser sends an HTTP request to the server.
  • Web server recognizes that this is a request for a JSP page, and passes the request to the JSP engine. By using the URL or .jsp file to complete.
  • JSP JSP engine load files from the disk, and then translate them into servlet. This conversion will simply switch all template text println () statements, and all JSP elements converted into Java code.
  • JSP servlet engine will be compiled into an executable class, and the original request is passed to the servlet engine.
  • A component of the Web server will be called servlet engine, and then load and execute the servlet class. During execution, servlet generate output in HTML format and embedded in the HTTP response to the Web on the server.
  • Web server in the form of static HTML pages the HTTP response back to your browser.
  • Ultimately, Web browser handles HTTP response dynamically generated HTML pages, as if the same process static pages.

Steps mentioned above can be represented by the following diagram:

Under normal circumstances, JSP engine checks to see if JSP servlet corresponding to the file already exists, and checks whether the file modification date earlier than the JSP servlet. If the JSP file modification date earlier than the corresponding servlet, then the container can determine the JSP file has not been modified and servlet valid. This makes the whole process compared to other scripting languages ​​(such as PHP) to a number of fast and efficient.

In general, JSP page is another way to write Java servlet instead become a programming expert. In addition to the explanation stage, JSP pages can be almost as an ordinary servlet to be treated.