This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

javaranch - Mock exam  RSS feed

 
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.

 
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.
 
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
 
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!