同一servlet的许多url模式 [英] many url-pattern for the same servlet
问题描述
我需要将相同的servlet映射到两个不同的url上.我使用netbeans 7.0.1来管理整个项目,因此我使用了它的友好界面来修改web.xml文件.创建的netbeans是这样的:
I need to map the same servlet on two different url. I used netbeans 7.0.1 for managing my whole project, so I used its friendly interface to modify the web.xml file. What netbeans created is this:
<servlet-mapping>
<servlet-name>fred</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>/url</url-pattern>
</servlet-mapping>
tomcat 5.5可以读取它而不会发出任何错误,但是只有第二种模式有效,而第一个模式将被忽略.
This is read by tomcat 5.5 without emitting any error, but only the second pattern works, while the first one is ignored.
Google搜索,我发现使用Tomcat的正确方法是:
Googling I found that the right way for tomcat is this one:
<servlet-mapping>
<servlet-name>fred</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fred</servlet-name>
<url-pattern>/url</url-pattern>
</servlet-mapping>
所以,我的问题是:这是tomcat中的错误吗?其他容器接受什么语法?
So, my questions: is this a bug in tomcat? What syntax do other containers accept?
推荐答案
我想这与容器/netbeans正在使用的servlet规范有更多关系,而不是与容器有关.您的Net Bean似乎正在使用规范2.5构造Servlet映射,因此您得到
I guess it has more to do with the servlet spec the container/netbeans is using rather than being an issue with the container. Your net beans seems to be using the spec 2.5 to construct the servlet mapping and hence you get
<servlet-mapping>
<servlet-name>fred</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>/url</url-pattern>
</servlet-mapping>
在此处.它说
以前的servlet架构版本仅允许一个url模式 过滤器映射.对于映射到多个URL的过滤器,这将导致不必要的 重复整个映射子句.
Previous versions of the servlet schema allows only a single url-pattern in a filter mapping.For filters mapped to multiple URLs this results in needless repetition of whole mapping clauses.
这篇关于同一servlet的许多url模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!