title: How are Servlet url mappings in web.xml used?
body: <p>I have a web.xml file with content:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;servlet&gt;
      &lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.mycompany.test1&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;servlet2&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.mycompany.test2&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/path/test&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;servlet2&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/path/test/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>I tried requests</p>
  
  <pre><code>.../path/test/abc 
  .../path/test
  </code></pre>
  
  <p>Both requests are processed by Servlet2. Why?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thank you guys for your help.
  I realised that behaviour depends on order of servlet-mapping declaration.
  I tried this web.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;servlet&gt;
      &lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.mycompany.test1&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;servlet2&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.mycompany.test2&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;servlet3&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.mycompany.test3&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;servlet4&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.mycompany.test4&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/path/test&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;servlet2&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/path/test/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;servlet3&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/path/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;servlet4&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/path&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>results:</p>
  
  <pre><code>.../path/test/abc - servlet2
  .../path/test/ - servlet2
  .../path/test - servlet2
  
  .../path/abc - servlet3
  .../path/ - servlet4
  .../path - servlet4
  </code></pre>