You are on page 1of 1

Question: JSP Life Cycle - explain.

Answer: JSP life cycle can be grouped into seven phases. 1. JSP Page Translation: A java servlet file is generated from the JSP source file. Generated servlet implements the interface javax.servlet.jsp.HttpJspPage. The interface HttpJspPage extends the interface JspPage. This interface JspPage extends the interface javax.servlet.Servlet. 2. JSP Page Compilation: The generated java servlet file is compiled into a java servlet class. The generated servlet class thus implements all the methods of the above said three (javax.servlet.jsp.HttpJspPage, JspPage, javax.servlet.Servlet) interfaces. 3. Class Loading: The java servlet class that was compiled from the JSP source is loaded into the container. 4. Instance Creation: An instance is created for the loaded servlet class. 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(). 5. jspInit( ) execution: This method is called when the instance is created and it is called only once during JSP life cycle. It is called for the servlet instance initialization. 6. _jspService() execution: This method is called for every request of this JSP during its life cycle. It passes the request and the response objects. _jspService() cannot be overridden. 7. jspDestroy() execution: This method is called when this JSP is destroyed and will not be available for future requests.

You might also like