my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes servlet startup order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "servlet startup order" Watch "servlet startup order" New topic
Author

servlet startup order

Stella Kim
Greenhorn

Joined: Jan 18, 2007
Posts: 25
What's the correct order of the following statements:

1) Initialize Servlets to load on startup in the web application deployment descriptor.

2) The contextInitilized method is called on listeners implementing ServletContextListener which have been instantiated.

3) Instantiate listeners defined in the web application DD

4) Initialize filters defined in the web application DD
[ January 18, 2007: Message edited by: flytothemoon ]

Kim<br />SCJP 1.4 (98%)<br />SCWCD (92%)
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
The correct order is as follows
First the container loads filters
Next container Loads Listeners
Then container loads sevlets
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
where did the 2nd point will fall in order


"Know where to find the solution and how to use it - that's the secret of success."
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
write a servlet who uses ServletContextListener and filter then check which one is loaded first(listener or ServletContextListener) by using System.out.println("string") method.
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
The correct order is as follows
First the container loads filters
Next container Loads Listeners

Then container loads sevlets

I'm afraid that's incorrect.

This is 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.

[ January 19, 2007: Message edited by: Sayak Banerjee ]

Turn on, tune in, drop out.
Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344
Yes.. I think Sayak Banerjee is correct.
First.. Listeners
Second..The contextInitilized method is called on listeners implementing ServletContextListener which have been instantiated.

Third.. Filter
Fourth.. Servlet


Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Stella Kim
Greenhorn

Joined: Jan 18, 2007
Posts: 25
Anyone can confirm this ?

Filter -- then Listener ?

or

Listener -- then Filter ?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
This has already been confirmed by the post from Sayak as he wrote the quote from Servlet 2.4 specs page 78. If its still not confirmed then see it yourself at page 78.

If you don't have the specs you can find the link here SCWCD Links
Stella Kim
Greenhorn

Joined: Jan 18, 2007
Posts: 25
Oh, sorry,
I didn't read carefully.

Thank you all
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: servlet startup order
 
Similar Threads
Confusion in Steps before a application start servicing client requests
Can anybody answer this question?
Please answer me this question.
Doubt on Session Attribute and Web Deployment
order in which listeners are called