I encountered a J2EE project written by others. When I come to the web.xml
, there are two different servlets mapped on the same URL pattern. I wonder the purpose of this approach. How exactly does that work and what's the puspose?
Here is the relevant part of the web.xml
:
<servlet>
<servlet-name>fileDownload</servlet-name>
<servlet-class>com.htsoft.core.web.servlet.FileDownloadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fileDownload</servlet-name>
<url-pattern>/file-download</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>fileDownLoad</servlet-name>
<servlet-class>com.kaiwii.oa.action.system.FileDownloadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fileDownLoad</servlet-name>
<url-pattern>/file-downLoad</url-pattern>
</servlet-mapping>
Only one servlet will get called; there's no mechanism I'm aware of for handling a single request with two servlets (nor am I sure what that would even mean).
Servlet URL patterns may overlap, but having two with the exact same URL doesn't make sense. I don't recall if the servlet spec explicitly disallows it, however matching stops at the first matching. The matching method is defined in the spec.
Servlet 2.4 spec PDF See p. 85+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With