wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Order of loading of web.xml components/elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Order of loading of web.xml components/elements" Watch "Order of loading of web.xml components/elements" New topic
Author

Order of loading of web.xml components/elements

nitin pai
Ranch Hand

Joined: May 30, 2006
Posts: 185
I have faced this question often in some mocks I had taken which asks about the order of loading that takes place for the different components.

Please tell me the order of class loading / instantiation which happen after a web application is deployed for all components / elements which can come in the web.xml (like servlets, listeners, filters, tags etc etc )

And one more question I have is does this order depend on the way the web.xml is written or is there a pre defined order which is fixed irregardless of the container?



Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I paste the specification's relevant part, which should answer both questions :

SRV.9.12 Web Application Deployment
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-onstartup
element values, and call each servlet instance�s init() method.


[My Blog]
All roads lead to JavaRanch
nitin pai
Ranch Hand

Joined: May 30, 2006
Posts: 185
Thanks Satou,

I should really read the specification I guess.

But what about the tag handler classes and tag files? When are they instantiated?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

At run-time, tag handler instances will be created and methods will be invoked in them.
 
Consider Paul's rocket mass heater.
 
subject: Order of loading of web.xml components/elements