Lifecycle of JSP - Java @ Desk

Friday, June 7, 2013

Lifecycle of JSP

JSP, Java server pages follows the lifecycle of a servlet itself. When a client request comes for a JSP page, it gets converted into a servlet.

It has following phases:



Container loads the class file
In this step, the container loads the class file and follows the servlet lifecycle. It runs the jspInit() method and initializes the servlet.

Container executes the request
In this step, new Thread is created to handle the client’s request and the servlets _jspService() method gets called and servlet returns the response back to the client. The first two steps, Translation and Compilation happens only once i.e. during the first client request. After first request, already translated class file is used by the container to handle the request.

The java class file that gets generated has following methods:

1) jspInt() : This method is called from init() method.
2) _jspService() : This method is called from servlet service() method. For each client request a seperate thread is created. Can't override this method
3) jspDestroy() : This is called from servlet's destroy() method.



Both jspInit() and jspDestroy() are allowed to override. To view example, click here.

To view Servlet Lifecycle, click here.








No comments:

Post a Comment