Let us take a look at the life-cycle of a JSP Page
• When a first request is made to the server the JSP files are compiled into servlets.
Java Source Generation and Compilation
• When a Web container receives a request for a JSP file, it passes the request to the JSP processor .
• If this is the first time the JSP file has been requested or if the compiled copy of the JSP file is not found, the JSP compiler generates and compiles a Java source file for the JSP file.
• The JSP processor puts the Java source and class file in the JSP processor directory.
• By default, the JSP syntax in a JSP file is converted to Java code that is added to the service() method of the generated class file.
RequestProcessing
• After the JSP processor places the servlet class file in the JSP processor directory, the Web container creates an instance of the servlet and calls the servlet service() method in response to the request.
• All subsequent requests for the JSP are handled by that instance of the servlet.
• When the Web container receives a request for a JSP file, the engine checks to determine whether the JSP file (.jsp) has changed since it was loaded.
• If it has changed, the Web container reloads the updated JSP file
• The newly loaded servlet instance receives the client request.
Termination
• When the Web container no longer needs the servlet or a new instance of the servlet is being reloaded, the Web container invokes the servlet’s destroy() method.
• The Web container can also call the destroy() method if the engine needs to conserve resources or a pending call to a servlet service() method exceeds the timeout.
• The Java Virtual Machine performs garbage collection after the destroy.

Leave a comment