1. 程式人生 > >過濾器配置多個url-pattern

過濾器配置多個url-pattern

最近做專案遇到一個Filter需要配置多個url-pattern,上網查了下資料,經測試,現總結下
一、完全錯誤的方式

  1. <filter>
  2.     <filter-name>authority</filter-name>
  3.     <filter-class>com.util.AuthorityFilter</filter-class>
  4. </filter>
  5. <filter-mapping>
  6.     <filter-name>authority</filter-name>
  7.     <url-pattern
    >/pages/cmm/*;/pages/genbill/*</url-pattern>
  8. </filter-mapping>


二、有一定作用,但不能實現需要的效果,只會過濾最下面配置的url-pattern。

  1. <filter>
  2.     <filter-name>authority</filter-name>
  3.     <filter-class>com.util.AuthorityFilter</filter-class>
  4. </filter>
  5. <filter-mapping>
  6.     <filter-name
    >authority</filter-name>
  7.     <url-pattern>/pages/cmm/*</url-pattern>
  8.        <url-pattern>/pages/genbill/*</url-pattern>
  9. </filter-mapping>

三、現在給出正確的配置方式

  1. <filter>
  2.     <filter-name>authority</filter-name>
  3.     <filter-class>com.util.AuthorityFilter</filter-class
    >
  4. </filter>
  5. <filter-mapping>
  6.     <filter-name>authority</filter-name>
  7.        <url-pattern>/pages/genbill/*</url-pattern>
  8. </filter-mapping>
  9. <filter-mapping>
  10.     <filter-name>authority</filter-name>
  11.     <url-pattern>/pages/cmm/*</url-pattern>
  12. </filter-mapping>