This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
A servlet's init(ServletConfig) method is called by the server immediately after the server constructs the servlet's instance. Depending on the server and its configuration, this can be at any of these times:
1.When the server starts 2.When the servlet is first requested, just before the service() method is invoked 3.At the request of the server administrator
In any case, init() is guaranteed to be called before the servlet handles its first request. The init() takes an object and gives it its servletness (by giving the servlet config).
Joined: Mar 02, 2008
Thanks,But this is with respect to init(ServletConfig).what about init()?
The javadocs of the GenericServlet.init() method mention when it will be called. Note that that method is not part of the Servlet interface, so the servlet container knows nothing about it - it is particular to the GenericServlet class.
init(ServletConfig) is defined in javax.servlet.Servlet interface.as this is implemeted by GenericServlet class ,the method is implemented in that class . this method is mainly used to save ((we have a ServletConfig instance declared in GenericServlet class)) the ServletConfig object particular to the invoked servlet.after it saved the ServletConfig object it delgates to init() method which is a convenience method to be overloaded by the invoking servlet. we have getServletConfig() method to get ServletConfig object. normally we call getServletConfig() method in our servelt to get ServletConfig object.
the main purpose of init() method is to be overloaded by the invoked servlet.
coming to your second question. your opinion is absolutely right.
thanks and regards<br />Santhi Bharath<br />SCJP 5.0, SCWCD 5.0