JSP life cycle can be divided into four phases: Translation, Initialization, execution and finalization.
Translation
In the translation phase, JSP engine checks for the JSP syntax and translates JSP page into its page implementation class if the syntax is correct. This class is actually a standard Java servlet. After that, JSP engine compiles the source file into class file that is ready to use.
If the container receives the request, it checks for the changes of the JSP page since it was last translated. If no changes was made, It just loads the servlet otherwise the process of check, translate and compile takes place again. Because the compilation process takes time so JSP engine wants to minimize it to increase the performance of the page processing.
Initialization
After the translation phase, JSP engine loads the class file and create an instance of of the servlet to handle processing of the initial request. JSP engines will call a method jspInit() to initialize the a servlet. jspInit method is generated during the translation phase which is normally used for initializing application-level parameters and resources. You can also overide this method by using declaration.
<%! public void jspInit(){ // put your custom code here } %>
Execution
After the initialization phase, the web container calls the method _jspService() to handle the request and returning a response to the client. Each request is handled is a separated thread. Be noted that all the scriptlets and expressions end up inside this method. The JSP directives and declaration are applied to the entire page so the are outside of this method.
Finalization
In the finalization phase, the web container calls the method jspDestroy(). This method is used to clean up memory and resources. Like jspInit() method, you can override thejspDestroy() method also to do your all clean up such as release the resources you loaded in the initialization phase....
<%! public void jspDestroy(){ // put your custom code here // to clean up resources } %>
In the JSP lifecycle, the destroy method is also invoked when the server shuts down
ReplyDeleteI have also started creating blog on java. Its in still new phase.
ReplyDeleteYou are invited to see my blog and put your valuable comments
http://javacodeimpl.blogspot.com
This is the first time I've been to your website.
ReplyDeleteThank you for posting more information.
Feel free to surf to my web blog ... tutor In Melbourne
Perfect explanation.. Thanks.. Please explain about Struts Life cycle
ReplyDelete