Pages

Tuesday, 25 September 2012

Working of the JSP Container


This article illustrates the working of JSP (Java Server Pages). A JSP page has to pass many stages before execution. A JSP container plays a vital role here. Lets discuss it in detail:

A jsp page exist in three forms or version, as explained below:

JSP Source Code: This is the version the developer actually writes. It consist of a text file with an extension of .jsp, and contains a mix of HTML template code, java language statements, and JSP directives and sections that describe how to generate a Web page to service a paticular request.

Java Source Code: The JSP container translates the JSP source code into the source code of an equivalent java servlet as needed. This source code is typically saved in a work area and is often helpful for debugging.

Compiled Java Class: Like any other java class, the generated servlet code is compiled into byte codes in a .class file, ready to be loaded and executed.

Something About JSP Container:

The JSP container manages each of these forms of the JSP page automatically, based on the timestamps of each file. In response to an HTTP request, the container checks to see if the .jsp source file has been modified since the .java source was last compiled. If so, the container retranslates the JSP source into java source and recompiles it.

Let us illustrate the process used by the JSP Container. When a request for the JSP page is made, the container first determines the name of the class corresponding to the .jsp file. If the class doesn’t exist or if it’s older than the .jsp file (meaning the jsp source has changed since it was last compiled), then the container creates java source code for an equivalent servlet and compiles it. If an instance of the servlet isn’t already running (or if the servlet was newly generated), the container load the servlet class and create an instance. Finally the container dispatches a thread to handle the current HTTP request in the loaded instance. So this process can be summarize as: 

JSP Source Code >>>> (translation occured) >>>> Generated Servlet Source Code >>>> (compilation occurred) >>>> Compiled Servlet Class

No comments:

Post a Comment