過濾器配置多個url-pattern
阿新 • • 發佈:2019-01-27
最近做專案遇到一個Filter需要配置多個url-pattern,上網查了下資料,經測試,現總結下
一、完全錯誤的方式
- <filter>
- <filter-name>authority</filter-name>
- <filter-class>com.util.AuthorityFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>authority</filter-name>
- <url-pattern
- </filter-mapping>
二、有一定作用,但不能實現需要的效果,只會過濾最下面配置的url-pattern。
- <filter>
- <filter-name>authority</filter-name>
- <filter-class>com.util.AuthorityFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name
- <url-pattern>/pages/cmm/*</url-pattern>
- <url-pattern>/pages/genbill/*</url-pattern>
- </filter-mapping>
三、現在給出正確的配置方式
- <filter>
- <filter-name>authority</filter-name>
- <filter-class>com.util.AuthorityFilter</filter-class
- </filter>
- <filter-mapping>
- <filter-name>authority</filter-name>
- <url-pattern>/pages/genbill/*</url-pattern>
- </filter-mapping>
- <filter-mapping>
- <filter-name>authority</filter-name>
- <url-pattern>/pages/cmm/*</url-pattern>
- </filter-mapping>