| Refresh | Home EGTry.com

servlet url patterson -- path prefix match take precedance over extension math


If a url request path match two servlets, one is by path prefix match and another by extension match, then the path prefix matching servlet wins.

servlet url mapping in web.xml

     <servlet-mapping>
    	<servlet-name>DefaultServlet</servlet-name>
    	<url-pattern>/</url-pattern>
  	</servlet-mapping>
    
    <servlet-mapping>
    <servlet-name>ExtensionMappingServlet</servlet-name>
   	<url-pattern>*.xml</url-pattern> 
  	</servlet-mapping>
  	
   <servlet-mapping>
    <servlet-name>PathMappingServlet</servlet-name>
   	<url-pattern>/hello/*</url-pattern>
   </servlet-mapping>
   


url matching examples

url matched servlet ContextPath ServletPath RequestPath
http://localhost:8080/dynamicweb111/ DefaultServlet /dynamicweb111 / /dynamicweb111/
http://localhost:8080/dynamicweb111/hello PathMappingServlet /dynamicweb111 /hello /dynamicweb111/hello
http://localhost:8080/dynamicweb111/hello.xml ExtensionMappingServlet /dynamicweb111 /hello.xml /dynamicweb111/hello.xml
http://localhost:8080/dynamicweb111/code/world.xml ExtensionMappingServlet /dynamicweb111 /code/world.xml /dynamicweb111/code/world.xml
http://localhost:8080/dynamicweb111/hello/world.xml PathMappingServlet /dynamicweb111 /hello /dynamicweb111/hello/world.xml