aspose file tools*
The moose likes Servlets and the fly likes which event occur first Servlet mapping or Servlet loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "which event occur first Servlet mapping or Servlet loading" Watch "which event occur first Servlet mapping or Servlet loading" New topic
Author

which event occur first Servlet mapping or Servlet loading

ganesh pol
Ranch Hand

Joined: Apr 29, 2005
Posts: 151
hi friends can any one tell me
which event occur first Servlet mapping or Servlet class loading?
i think Servlet mapping occur first then servlet class loading occur
please tell me i am correct or not?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Take a look at the servlet spec. The link is in my signature.
It will show you the order that elements need to appear in the deployment descriptor (web.xml)
The web.xml (in Tomcat anyway) is parsed using a SAX parser which means that the events are fired in the order in which they appear in the xml file.

The servlet elements appear before the mappings.

I've also seen mappings fail if they can't find the servlet to which the refer. This would tell me that the servlet needs to be loaded before a mapping to it can exist.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ana Nava
Greenhorn

Joined: May 25, 2004
Posts: 24
In Servlet Spec 2.4, page 25 under the title SRV.2.3.1 Loading and Instantiation, following is stated :

The servlet container is responsible for loading and instantiating servlets. The loading and instantiation can occur when the container is started, or delayed until the container determines the servlet is needed to service a request. When the servlet engine is started, needed servlet classes must be located by the servlet container.


From this I infer that, when the servlet engine starts it "locates" all the servlet classes via <servlet> element from web.xml file.

But the "loading" of the servlet class, entirely depends on the container's implementation. If the container is implemented to load all the servlet class when it is started, then the loading would precede the mapping. If the container is implemented to load the servlet class, only when it is needed to service a request, then mapping would precede the loading.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"Load" / "LOCATE"

Thats a good distinction.
There would be no point in the load-on-startup attribute otherwise.

Thanks
[ June 21, 2005: Message edited by: Ben Souther ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which event occur first Servlet mapping or Servlet loading