In the previous tutorial, we discussed the life cycle of Servlet. Let us discuss the life cycle of JSP in this tutorial. First, a JSP file is converted into Servlet and then the corresponding servlet gets processed by Server.
The steps in the life cycle of JSP are:
Step 1: Translation
When a JSP file is loaded into a Web server, the JSP file is translated into Servlet. After receiving a client request for JSP resource, the container checks whether the servlet class is older than the JSP page. If the file is older, the container translates the JSP into a Servlet, otherwise, the translation phase is skipped.
Step 2: Compilation
After the translation of the JSP file to Servlet, the Servlet file is compiled.
Step 3: Loading
Then, the compiled class file is loaded into the container.
Step 4: Instantiation and jspInit() method
After loading, the servlet class is instantiated and the
jspInit()
method is called to instantiate the Servlet. Only one instance is created for each class.
public void jspInit() { //code to intialize Servlet instances }
Step 5: Invoking jspService()
For each client request, a new thread is created, which invokes the
_jspService()
method, with
HttpServletRequest
and
HttpServletRespnse
objects as parameters.
void _jspService( HttpServletRequest req, HttpServletResponse res) { //code goes here }
Step 6: Invoking jspDestroy()
If the JSP file is deleted from the container and the server is shut
down, the
jspDestroy()
method is invoked to destroy the instance of the servlet class.
public void jspDestory() { //code to remove the instances of servlet class }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.