I have two servlets 'ExtensionServlet' and 'PatternServlet' and a static html page. The HTML code is given below.
<html>
<head>
<title>
Resolve servlet ambiguity
</title>
</head>
<body>
<form action="servlets/form.col" method="POST">
<input type="submit" value="Goto Servlet">
</form>
</body>
</html>
The Deployment descriptor is as follows.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<servlet>
<servlet-name>Extension Servlet</servlet-name>
<servlet-class>ExtensionServlet</servlet-class>
<servlet-name>Pattern Servlet</servlet-name>
<servlet-class>PatternServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Extension Servlet</servlet-name>
<url-pattern>*.col</url-pattern>
<servlet-name>Pattern Servlet</servlet-name>
<url-pattern>/servlets/*</url-pattern>
</servlet-mapping>
</web-app>
When I click the button in the HTML page it leads to "PatternServlet". If I rearrange the servlet order in the deployment descriptor as below, it goes to "ExtensionServlet"
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<servlet>
<servlet-name>Pattern Servlet</servlet-name>
<servlet-class>PatternServlet</servlet-class>
<servlet-name>Extension Servlet</servlet-name>
<servlet-class>ExtensionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Pattern Servlet</servlet-name>
<url-pattern>/servlets/*</url-pattern>
<servlet-name>Extension Servlet</servlet-name>
<url-pattern>*.col</url-pattern>
</servlet-mapping>
</web-app>
Can anyone please explain this behavior?
Tomcat 6.0.20 JVM 1.6.0_15-b03