• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javaranch - Mock exam

 
Elan Ram
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Watch out this question:

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:

The ordering of the DD is listener then servlet.

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to Servlet 2.4 spec, answer should be 2. But it says 3 with following explanation:

The ordering of the DD is listener then servlet.

That's absolutely wrong.

The correct answer is 3 because the <servlet-mapping> element is missing....it's easily overlooked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic