Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

servlet life cycle mixed with listeners and filters  RSS feed

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this question from jdiscuss.com, wonder if anyone can give me a correct question and short explanation?


Select the correct sequence of actions that a servlet container performs before servicing any request.

1. Instantiate listeners defined in the deployment descriptor.
2. Initialize filters defined in the deployment descriptor.
3. Initialize servlets that are set to load on startup.
4. Call the contextInitialized method on the listeners implementing ServletContextListener interface.



Thanks
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listeners are shared by all applications and launched first. If one of the listeners is application listener then its contextInitialized method will be called to do some application-class initialization.

Filters are always launched before servlets cause they intercept servlets' requests and act as preprocessors.

So the correct sequence is 1,4,2,3.

Dan
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.
 
Look ma! I'm selling my stuff!
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!