过滤器映射到最后一个路径段
filter mapping to last path segment
我正在尝试将过滤器映射到 web.xml 中的特定 url。问题是 url 中有一个动态路径段,我只需要将我的过滤器映射到以特定路径结尾的 URL。对于给定的网址:
http://company.com/webApp/aaa/end
http://company.com/webApp/bbb/end
http://company.com/webApp/ccc/end
我需要像这样映射一个 servlet:
<filter id="EndFilter">
<filter-name>EndFilter</filter-name>
<filter-class>com.company.EndFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EndFilter</filter-name>
<url-pattern>*/end</url-pattern>
</filter-mapping>
我知道 */ 不是有效的通配符,但我不知道这种类型的映射是否可行。很容易将 URL 映射到资源,例如以 *.png 或 *.jpeg 通配符结尾的图片,但我找不到映射简单 url 路径段的方法。
来自servlet 3.1 specification chapter 12:
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/. 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.
所以看起来这是不可能的。
我正在尝试将过滤器映射到 web.xml 中的特定 url。问题是 url 中有一个动态路径段,我只需要将我的过滤器映射到以特定路径结尾的 URL。对于给定的网址:
http://company.com/webApp/aaa/end
http://company.com/webApp/bbb/end
http://company.com/webApp/ccc/end
我需要像这样映射一个 servlet:
<filter id="EndFilter">
<filter-name>EndFilter</filter-name>
<filter-class>com.company.EndFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EndFilter</filter-name>
<url-pattern>*/end</url-pattern>
</filter-mapping>
我知道 */ 不是有效的通配符,但我不知道这种类型的映射是否可行。很容易将 URL 映射到资源,例如以 *.png 或 *.jpeg 通配符结尾的图片,但我找不到映射简单 url 路径段的方法。
来自servlet 3.1 specification chapter 12:
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/. 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.
所以看起来这是不可能的。