Forward过滤器

   <filter>

    <filter-name>PermissionFilter</filter-name>

    <filter-class>xx.xx.PermissionFilter</filter-class>

    </filter>

    <filter-mapping>

    <filter-name>PermissionFilter</filter-name>

    <servlet-name>目标资源一</servlet-name>

    </filter-mapping>

    <filter-mapping>

    <filter-name>PermissionFilter</filter-name>

    <servlet-name>目标资源二</servlet-name>

    </filter-mapping>

 

 

目标资源一是客户端直接访问,能被过滤.

而当目标资源二是被转发过来的,这时过滤器就不能过滤目标资源二

其实上面的配置等价于:

 

 

   <filter>

    <filter-name>PermissionFilter</filter-name>

    <filter-class>xx.xx.PermissionFilter</filter-class>

    </filter>

    <filter-mapping>

    <filter-name>PermissionFilter</filter-name>

    <servlet-name>目标资源一</servlet-name>

    <dispatcher>REQUEST</dispatcher>

    </filter-mapping>

    <filter-mapping>

    <filter-name>PermissionFilter</filter-name>

    <servlet-name>目标资源二</servlet-name>

    <dispatcher>REQUEST</dispatcher>

    </filter-mapping>

 

当如下配置:

 

   <filter>

    <filter-name>PermissionFilter</filter-name>

    <filter-class>xx.xx.PermissionFilter</filter-class>

    </filter>

    <filter-mapping>

    <filter-name>PermissionFilter</filter-name>

    <servlet-name>目标资源一</servlet-name>

    <dispatcher>REQUEST</dispatcher>

    </filter-mapping>

    <filter-mapping>

    <filter-name>PermissionFilter</filter-name>

    <servlet-name>目标资源二</servlet-name>

    <dispatcher>forword</dispatcher>

    </filter-mapping>

 

 

我们看对目标资源二过滤的配置方式,这时过滤方式为forward,也就是说会对转发到目标资源二的请求过滤,如果直接访问目标资源二,过滤器将不起作用。

 

 

你可能感兴趣的:(servlet)