zoukankan      html  css  js  c++  java
  • JAVA WEB:一个Filter配置多个url-pattern

    最近做项目遇到一个Filter需要配置多个url-pattern,上网查了下资料,经测试,现总结下 

    一、完全错误的方式 
    Java代码
    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。 

    Java代码 
    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>  

    三、现在给出正确的配置方式 
    Java代码
    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> 

  • 相关阅读:
    MySQL数据库 : 高级查询
    ElasticSearch : High Rest Api 使用
    Java : JavaWeb和Tomcat相关
    Linux : Ubuntu 安装 RabbitMQ
    Spring : Spring Security
    Java : logback简单配置
    Spring : JPA的单独使用
    Java : Netty 入门案例
    python__PIP : 安装第三方库
    好文章收藏(持续更新)
  • 原文地址:https://www.cnblogs.com/xieyuan/p/3787367.html
Copyright © 2011-2022 走看看