What is JSP life cycle?
Life cycle of JSP (Java Server Page),after translated it works like servlet.It contain 7 phases-
1.Page Translation ? The page is parsed and a java file containing the corresponding servlet is created.
2.Page Compilation ?The java file is compiled and java servlet class is created.
3.Load Class ?The compiled class is loaded.
4.Create Instance ? An instance of the servlet class is created.
5.Call jspInit()- This method is called before any other method to initialisation. This method is called only one time during JSP life cycle.
6.Call _jspServices()- This method is called for each request.
7.Call jspDestroy() ?his method is called when the servlet container decides to take the servlet out of service.
JSPÔ??s life cycle can be grouped into following phases.
A java servlet file is generated from the JSP source file. This is the first step in its tedious multiple phase life cycle. In the translation phase, the container validates the syntactic correctness of the JSP pages and tag files. The container interprets the standard directives and actions, and the custom actions referencing tag libraries used in the page.
The generated java servlet file is compiled into a java servlet class.
Note: The translation of a JSP source page into its implementation class can happen at any time between initial deployment of the JSP page into the JSP container and the receipt and processing of a client request for the target JSP page.
The java servlet class that was compiled from the JSP source is loaded into the container.
In the execution phase the container manages one or more instances of this class in response to requests and other events. The interface JspPage contains jspInit() and jspDestroy(). The JSP specification has provided a special interface HttpJspPage for JSP pages serving HTTP requests and this interface contains _jspService().
jspInit() method is called immediately after the instance was created. It is called only once during JSP life cycle.
This method is called for every request of this JSP during its life cycle. This is where it serves the purpose of creation. Oops! it has to pass through all the above steps to reach this phase. It passes the request and the response objects. _jspService() cannot be overridden.
This method is called when this JSP is destroyed. With this call the servlet serves its purpose and submits itself to heaven (garbage collection). This is the end of jsp life cycle.
jspInit(), _jspService() and jspDestroy() are called the life cycle methods of the JSP.