Web.xml:url-pattern 标签彼此相关吗?
<servlet-mapping>
<servlet-name>myName</servlet-name>
<url-pattern>/aName</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
...
<url-pattern>
/*
</url-pattern>
</web-resource-collection>
...
</security-constraint>
这是 web.xml 的摘录(使用它来配置 jboss/tomcat web 服务)。只是想知道 web-resource-collection
中的 url-pattern
是否相对于 servlet-mapping
中的 url-pattern
代码>.
<servlet-mapping>
<servlet-name>myName</servlet-name>
<url-pattern>/aName</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
...
<url-pattern>
/*
</url-pattern>
</web-resource-collection>
...
</security-constraint>
This is an excerpt from web.xml (using it to configure a jboss/tomcat webservice). Just wondering if the url-pattern
in web-resource-collection
is relative to the url-pattern
in servlet-mapping
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用于为给定请求选择约束的
url-pattern
与任何事物都无关。 Servlet 规范中有趣的部分是:和:
The
url-pattern
used to select the constraints for a given request are not relative to anything. The interesting parts of the Servlet spec here are:And:
对我来说,security-constraint/web-resource-collection/url-pattern 与 servlet-mapping/url-pattern 不 是有道理的,原因如下:web.xml 中可能有多个 servlet-mapping 元素,在这种情况下,不清楚是哪个 servlet-mapping/url-pattern< /em> 用于解析相对 URI,如果是的话。
(只是猜测 - 我还没有在 tomcat 中使用安全约束)。
It would make sense to me that the security-constraint/web-resource-collection/url-pattern is not relative to the servlet-mapping/url-pattern, for the following reason: there can be several servlet-mapping elements in web.xml, in which case it would not be clear which servlet-mapping/url-pattern to take to resolve the relative URI, were it one.
(Just a guess - I have not used security constraints in tomcat yet).
不,它们彼此没有关系;无法将给定的 servlet-mapping 绑定到安全约束。两者都应用于给定的 URL 模式,安全约束也可以仅应用于特定的 HTTP 方法(GET、POST...),因此它们是相当独立的。
这两个元素均在 Servlet 规范 中定义和描述。您可能需要阅读有关安全性的 SRV.12.8 部分以及有关 url-pattern 元素的详细信息。
No, they are not relative to each other; there is no way to bind a given servlet-mapping to a security-constraint. Both are applied to a given URL pattern, security constraint can also be applied only to specific HTTP methods (GET, POST, ...) so they are quite independent.
Both elements are defined and described in the Servlet specification. You might want to read sections SRV.12.8 about security, and details about the url-pattern element.