强制首先执行“WebFilter”

时间:2012-06-01 13:10:11

标签: java java-ee servlet-filters

在我的web.xml

中考虑以下过滤器映射
<filter-mapping>
    <filter-name>rememberMeCookieFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>mustBeSignedInFilter</filter-name>
    <url-pattern>/private/*</url-pattern>
</filter-mapping>

据我所做的测试,如果我转到/private/account.jsp,必须首先执行mustBeSignedInFilter(from what I could read, it's because the path is more specific)。我需要先记住rememberMeCookieFilter。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

您将过滤器映射与servlet映射混淆。与URL匹配的所有过滤器的执行顺序与在web.xml中指定过滤器映射的顺序相同。因此,交换过滤器映射,它将按预期工作。

<filter-mapping>
    <filter-name>mustBeSignedInFilter</filter-name>
    <url-pattern>/private/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>rememberMeCookieFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>