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?
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.
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.