Sunday, January 25, 2015

The JSP life cycle

A JSP life cycle can be defined as the entire process from its creation till the destruction which is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet.

There are several main processe that will be performed in a jsp life cycle

CompilationInitializationExecutionCleanup



These are much similar to the servlet life cycle



JSP Compilation

If the JSP page haven’t be compiled before then the JSP engine will compile the JSP code. The advantage of JSP is that if it has been compiled once and if there are no any changes made, then the JSP engine does not need to compile the coding again.

JSP Initialization

When a container loads a jsp code it invokes the jspint() method. Typically initialization is performed only once and as with the servlet init method, you generally initialize database connections, open files, and create lookup tables in the jspInit method.

JSP Execution

This phase of the JSP life cycle represents all interactions with requests until the JSP is destroyed.Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the _jspService() method in the JSP.The _jspService() method takes an HttpServletRequest and an HttpServletResponse as its parameters as follows:


JSP Cleanup

The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container.
The jspDestroy() method is the JSP equivalent of the destroy method for servlets. Override jspDestroy when you need to perform any cleanup, such as releasing database connections or closing open files.
The jspDestroy() method has the following form: 

No comments:

Post a Comment