Thanks for the links , going through them I have compiled this answer . Let us see a sample web.xml
:
Case 1:
<servlet-mapping>
`
<servlet-name>servlet1</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>servlet2</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
In this case all requests /context/
, /context/anything
and /context/sample.do
will invoke servlet2
.
Case 2:
<servlet-mapping>
`
<servlet-name>servlet1</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>servlet2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
In this case requests like /context/
, /context/anything
invokes servlet2
and /context/sample.do
will invoke servlet1
.