Question: Explain the life-cycle methods in JSP?

By: Guru Singh Printer Friendly Format    

Question: Explain the life-cycle methods in JSP?

Answer:  The generated servlet class for a JSP page implements the HttpJspPage interface of the javax.servlet.jsp package. The HttpJspPage interface extends the JspPage interface which inturn extends the Servlet interface of the javax.servlet package. The generated servlet class thus implements all the methods of these three interfaces. The JspPage interface declares only two mehtods - jspInit() and jspDestroy() that must be implemented by all JSP pages regardless of the client-server protocol. However the JSP specification has provided the HttpJspPage interfaec specifically for the JSp pages serving HTTP requests. This interface declares one method _jspService().

The jspInit()- The container calls the jspInit() to initialize te servlet instance.It is called before any other method, and is called only once for a servlet instance.

The _jspservice()- The container calls the _jspservice() for each request, passing it the request and the response objects.

The jspDestroy()- The container calls this when it decides take the instance out of service. It is the last method called n the servlet instance.





Most Viewed Articles (in Interview )

What are the services provided by a container?

Question: What is the directory structure of a web application?

Question: What is an Expression tag in JSP?

Types of Interviews

Interview Question: What is the difference between JavaBean and EJB?

Interview Question: What is local interface. How values will be passed?

Interview Question: What is Message Driven Bean?

Interview Question: What is deployment descriptor?

Interview Question: How many EJB Objects are created for a Bean?

Interview Question: What is re-entrant. Is session beans reentrant. Is entity beans reentrant?

Interview Question: Is Decorator an EJB design pattern?

Interview Question: What is the difference between sessioncontext and entitycontext?

Interview Question: What is the difference between ejbCreate() and ejbPostCreate?

Interview Question: What are the optional clauses in EJB QL?

Interview Question: What is Local client view in EJB?

Latest Articles (in Interview)

Comment on this tutorial