11
<servlet-mapping>
  <servlet-name> s1</servlet-name>
  <url-pattern> /abc </url-pattern>
</servlet-mapping>

<servlet-mapping>
  <servlet-name> s2</servlet-name>
  <url-pattern> /abc </url-pattern>
</servlet-mapping>

<servlet-mapping>
  <servlet-name> s3</servlet-name>
  <url-pattern> /* </url-pattern>
</servlet-mapping>

Which servlet will be called if a request /abc comes?and why?

MaDa
  • 10,511
  • 9
  • 46
  • 84
Xyzxyz Xyz
  • 415
  • 1
  • 5
  • 6

1 Answers1

16

Check this. In short:

  • if the mappings have exactly the same pattern, there is no guarantee which servlet one will be invoked. So avoid that.
  • If the patterns are overlapping, the most specific one is picked. (/abc is more specific than /*)
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Nice explanation, and the link provided is awesome, simple to grasp. – CuriousMind Apr 16 '16 at 19:47
  • Does the same thing apply for url-patter in filter-mapping ? – lads Sep 05 '18 at 08:13
  • @Bozho the link doesn't work anymore. Here's wayback machine copy https://web.archive.org/web/20160224184048/http://docs.roguewave.com/hydraexpress/3.5.0/html/rwsfservletug/4-3.html – Chris R Feb 06 '20 at 10:49