gpt4 book ai didi

java - web.xml 中的 url-pattern 问题

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:41:14 26 4
gpt4 key购买 nike

我在web.xml中的过滤器映射如下:

  <filter>
<filter-name>LoginCheckFilter</filter-name>
<filter-class>com.tutorial.filter.LoginCheckFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginCheckFilter</filter-name>
<url-pattern>/admin*</url-pattern>
</filter-mapping>

当我运行我的应用程序并点击 http://localhost:8080/admin 时,我的过滤器没有被执行。我无法理解为什么。

图案有没有问题。此外,如果我从模式中删除 '*',则过滤器会在点击上面的 url 时执行。

需要这方面的帮助。谢谢。

最佳答案

规范(第 12.2 段)说明如下:

In the Web application deployment descriptor, the following syntax is used to define mappings:

  • A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.

  • A string beginning with a ‘*.’ prefix is used as an extension mapping.

  • The empty string ("") is a special URL pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port/<contextroot>/. In this case the path info is ’/’ and the servlet path and context path is empty string (““).

  • A string containing only the ’/’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.

  • All other strings are used for exact matches only.

所以 *按字面意思理解,除非模式以 /* 结尾或以 *. 开头

关于java - web.xml 中的 url-pattern 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11023809/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com