When the servlet gets initalized the container willcall init(ServletConfig) to pass the configuartion info to the servlet; but what is the use of init() when will it be called.
One More Question. when the request is submitted the request goes to service method and based on the request methods doGet or doPost will be called is that correct.
Joined: Dec 16, 2007
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()?
Joined: Mar 22, 2005
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.