When a web application is deployed into a container, the following steps must be performed, in this order, before the web application begins processing client requests. 1. Instantiate an instance of each event listener identified by a <listener> element in the deployment descriptor. 2. For instantiated listener instances that implement ServletContextListener, call the contextInitialized() method. 3. Instantiate an instance of each filter identified by a <filter> element in the deployment descriptor and call each filter instance�s init() method. 4. Instantiate an instance of each servlet identified by a <servlet> element that includes a <load-on-startup> element in the order defined by the load-onstartup element values, and call each servlet instance�s init() method.
Event listeners are instantiated even before the initialization of the servletContext. The web container creates a single instance for each listener class declared in the web.xml file. If the same listener is declared twice in web.xml, two instances are created and so on. Different events can be triggered to the same listener instance if it implements the appropriate interfaces. A listener that implements only HttpSessionBindingListener is not required to be declared in web.xml.
There exist two service methods in the HttpServlet: * protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException Defined to be http dependent,
and the one declared in the Servlet interface (which is protocol independent): * public void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws ServletException, IOException
To process a client request, the web container calls the public service method, it calls in turn the protected service method which calls the appropriate doXXX(...) method.