过滤器映射问题

发布于 2024-12-22 00:41:27 字数 657 浏览 0 评论 0原文

我正在为我的项目使用一些过滤器映射。下面的过滤器模式命中了过滤器

<filter-mapping>
       <filter-name>wygUserCheckFilter</filter-name>
       <url-pattern>*.jsp</url-pattern>
</filter-mapping>

<filter-mapping>
       <filter-name>wygUserCheckFilter</filter-name>
       <url-pattern>/myProject/MyDisplay.jsp</url-pattern>
</filter-mapping>

,但下面的过滤器模式没有命中过滤器,

<filter-mapping>
       <filter-name>wygUserCheckFilter</filter-name>
       <url-pattern>/myProject/*.jsp</url-pattern>
</filter-mapping>

为什么会这样?

I am using a some filter mapping for my project . The following filter pattens hit the filter

<filter-mapping>
       <filter-name>wygUserCheckFilter</filter-name>
       <url-pattern>*.jsp</url-pattern>
</filter-mapping>

<filter-mapping>
       <filter-name>wygUserCheckFilter</filter-name>
       <url-pattern>/myProject/MyDisplay.jsp</url-pattern>
</filter-mapping>

But the one below doesn't hit the filter

<filter-mapping>
       <filter-name>wygUserCheckFilter</filter-name>
       <url-pattern>/myProject/*.jsp</url-pattern>
</filter-mapping>

Why is this so ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙女 2024-12-29 00:41:27

因为模式中间的 * 只匹配 * 字符。只有 /myProject/*.jsp-pattern 的匹配 url 是完全相同的字符串。 * 仅在以下情况下才具有特殊含义(Servlet 2.4 规范):

  • 以“/”字符开头并以“/*”结尾的字符串
    后缀用于路径映射。
  • 以“*”开头的字符串。
    前缀用作扩展映射。
  • 仅包含
    “/”字符表示应用程序的“默认”servlet。在
    在这种情况下,Servlet 路径是请求 URI 减去上下文路径
    并且路径信息为空。
  • 所有其他字符串均用于精确
    仅匹配。

Because * in the middle of the pattern matches only to the * character. Only matching url for /myProject/*.jsp-pattern is exactly same string. * does have special meaning only in the following cases (Servlet 2.4 Specification):

  • 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.
  • 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 con- text path
    and the path info is null.
  • All other strings are used for exact
    matches only.
丘比特射中我 2024-12-29 00:41:27

来自 Servlet 2.5 规范:

SRV.11.2

映射规范

在Web应用程序部署中
描述符,以下语法用于定义映射:

  • 以“/”字符开头并以“/*”后缀结尾的字符串用于路径映射。
  • 以“*”开头的字符串。前缀用作扩展映射。
  • 仅包含“/”字符的字符串表示应用程序的“默认”servlet。在本例中,servlet 路径
    是请求 URI 减去上下文路径,路径信息是
    空。
  • 所有其他字符串仅用于精确匹配。

From Servlet 2.5 spec:

SRV.11.2

Specification of Mappings

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.
  • 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文