Question Bank ID : 52 Section 3 - The Servlet Container Model <web-app> <servlet> ..... </servlet> <listener> <listener-class>com.javaranch.LogListener</listener-class> </listener> </web-app>
The above entry in the Deployment Descriptor(DD) will result in which of the following?
Options: 1) Provide a Log Servlet for the entire application. 2) Create a listener as defined by the com.javaranch.LogListener class. 3) The webapp will not be loaded due to a parse exception of the DD. 4) Log all session information as they occur.
According to Servlet 2.4 spec, answer should be 2. But it says 3 with following explanation:
In 2.4 inside container listeners are loaded first then fiters are loaded and atlast servlets are loaded.
[code] case 1-: <servlet> <servlet-name></servlet-name> <servlet-class></servlet-class> </servlet>
case 2-: <servlet> <servlet-class></servlet-class> <servlet-name></servlet-name> </servlet> [\code] In DD ordering does not matter as shown above Above case 1 and case 2 are both same. But filters are loaded as they are specified in DD.
since we are on that topic, i have something important to share with all of you,
Here's something from Servlet Spec. 2.4 --Page 78 ____________________________________________________________________________ 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.
� Instantiate an instance of each event listener identified by a <listener> element in the deployment descriptor.
� For instantiated listener instances that implement ServletContextListener, call the contextInitialized() method.
� Instantiate an instance of each filter identified by a <filter> element in the deployment descriptor and call each filter instance�s init() method.
� 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-on-startup element values, and call each servlet instance�s init() method.
so, to sum up, the order is -
listeners context listeners filters servlets
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ] Performance is a compulsion, not a option, if my existence is to be justified.