| Author |
servlet life cycle
|
ALaxmi Shankaran
Greenhorn
Joined: Feb 23, 2004
Posts: 26
|
|
In many interviews there is frequently asked question about life cycle of the servlet I know the init(),service(), and destory() methods well But how to answer this question up to the point (how much scope) And please can u explain about Do not override service() method.
|
 |
jai gurudev
Greenhorn
Joined: May 28, 2004
Posts: 20
|
|
Originally posted by ALaxmi Shankaran: In many interviews there is frequently asked question about life cycle of the servlet I know the init(),service(), and destory() methods well But how to answer this question up to the point (how much scope) And please can u explain about Do not override service() method.
Reply: if they ask servlet life cycle tell in details of each methods like init() will call first time and it intialize one time and then it calls service method.explain about init()... like: {don't explain like this study this and tell in your words} The init() method is typically used to perform servlet initialization--creating or loading objects that are used by the servlet in the handling of its requests. Why not use a constructor instead? Well, in JDK 1.0 (for which servlets were originally written), constructors for dynamically loaded Java classes (such as servlets) couldn't accept arguments. So, in order to provide a new servlet any information about itself and its environment, a server had to call a servlet's init() method and pass along an object that implements the ServletConfig interface. Also, Java doesn't allow interfaces to declare constructors. This means that the javax.servlet.Servlet interface cannot declare a constructor that accepts a ServletConfig parameter. what servlet will do: 1)Create and initialize the servlet. -init() 2)Handle zero or more service calls from clients. -Servie 3)Destroy the servlet and then garbage collect it. -destroy Answer for your question here: init()Called only once during the initialization of the Servlet. destroy()Called only once when Servlet instance is about to be destroyed. service()Do not override this method. doGet(), doPost(), doPut(), doDelete(), doOptions, doTrace()These methods are called according to the type of HTTP request received. Override them to generate your own response. thanks mail me if u want any further answer: jai gurudev
|
 |
 |
|
|
subject: servlet life cycle
|
|
|