将两个不同的servlet映射到相同的URL模式 [英] Having two different servlets mapped on the same URL pattern

查看:715
本文介绍了将两个不同的servlet映射到相同的URL模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了其他人编写的J2EE项目。当我来到 web.xml 时,有两个不同的servlet映射在相同的URL模式上。我想知道这种方法的目的。具体如何起作用以及它是什么?

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?

以下是 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>  


推荐答案

只有一个servlet会被调用;没有机制我知道用两个servlet处理单个请求(我也不确定这甚至意味着什么)。

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模式可能重叠,但是拥有两个完全相同的URL是没有意义的。我不记得servlet规范是否明确不允许它,但匹配在第一次匹配时停止。匹配方法在规范中定义。

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规范PDF 请参见p。 85 +

Servlet 2.4 spec PDF See p. 85+

这篇关于将两个不同的servlet映射到相同的URL模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆