title: Servlet Mapping using web.xml
body: <p>I have a confusion regarding the structure of the web.xml for the servlet mapping, I don't have any problem by executing it but I am trying to figure it how why we have such a pattern in the deployment descriptor. </p>
  
  <pre><code>&lt;web-app&gt;
      &lt;servlet&gt;
           &lt;servlet-name&gt;Servlet1&lt;/servlet-name&gt;
           &lt;servlet-path&gt;foo.Servlet&lt;/servlet-path&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
           &lt;servlet-name&gt;Servlet1&lt;/servlet-name&gt;
           &lt;url-pattern&gt;/enroll&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Now as far as my understanding whenever a request is comes for url-pattern "/enroll", servlet container is going to match the servlet-name with the url-pattern and will try to find the corresponding servlet-path and will forward the control to foo.Servlet. so basically there would be two passes one for finding servlet-name and another for servlet-path, my question is if container is designed to work in the following way</p>
  
  <pre><code>&lt;web-app&gt;
          &lt;servlet&gt;
               &lt;servlet-name&gt;foo.Servlet&lt;/servlet-path&gt;
               &lt;url-pattern&gt;/enroll&lt;/url-pattern&gt;
          &lt;/servlet&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>what would be the drawback if we use the following approach. Wouldn't that be more efficient and the response time would be fast.</p>