Mechanism of init method for servlet initialisation

Hi all!

I have some doubts about init method in servlet initialization.

1. if init method is not overridden the which version of init method is called by Container?

init() or init(ServletConfig)

2. when init() version of init method is overridden then how Container get ServletConfig object for that servlet?

Thaks...

[355 byte] By [_abhia] at [2007-11-26 18:16:11]
# 1

In order to initialize a Servlet, a server application loads the Servlet class (and probably other classes which are referenced by the Servlet) and creates an instance by calling the no-args constructor. Then it calls the Servlet's init(ServletConfig config) method. The Servlet should performe one-time setup procedures in this method and store the ServletConfig object so that it can be retrieved later by calling the Servlet's getServletConfig() method. This is handled by GenericServlet. Servlets which extend GenericServlet (or its subclass HttpServlet) should call super.init(config) at the beginning of the init method to make use of this feature. The ServletConfig object contains Servlet parameters and a reference to the Servlet's ServletContext. The init method is guaranteed to be called only once during the Servlet's lifecycle. It does not need to be thread-safe because the service method will not be called until the call to init returns.

MeTitus

Me_Titusa at 2007-7-9 5:49:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...