• 自定义filter包


    在有些时候,你可能需要以你的所有项目进行全局的过滤。

    因为你的项目可以设计到互相的依赖和调用 。

    修改在tomcat下的conf下的web.xml文件。和在原来的web-inif下的修改一样,添加filter.

    然后将你的filter打包成jar,放在tomcat下的lib目录下,如果你知道tomcat的lib目录的作用的话。

    1. <filter>  
    2.         <filter-name>appFilter</filter-name>  
    3.         <filter-class>com.common.AppFilter</filter-class>  
    4.     </filter>  
    5.     <filter-mapping>  
    6.         <filter-name>appFilter</filter-name>  
    7.         <url-pattern>/*</url-pattern>  
    8.         <dispatcher>REQUEST</dispatcher>  
    9.         <dispatcher>FORWARD</dispatcher>  
    10.         <dispatcher>INCLUDE</dispatcher>  
    11.     </filter-mapping>  
    1. public class PathFilter implements Filter {  
    2.   
    3.     public void destroy() {}  
    4.   
    5.     public void doFilter(ServletRequest request, ServletResponse response,  
    6.             FilterChain chain) throws IOException, ServletException {  
    7.   
    8.         HttpServletRequest req      = (HttpServletRequest)request;   
    9.         HttpServletResponse resp    = (HttpServletResponse)response;   
    10.         String uri = req.getRequestURI();  
    11.           
    12.         if(uri.endsWith("home.htm")){  
    13.             resp.sendRedirect("/hdsst/home/index.jsp");  
    14.         }  
    15.           
    16.         chain.doFilter(req,resp);  
    17.     }  
    18.       
    19.     public void init(FilterConfig filterConfig) throws ServletException {}  
    20.   
    21. }  
     
  • 相关阅读:
    php基本语法与安装
    面向对象编程 es5和es6的构造函数
    利用正则搜索替换
    正则特殊符号
    正则边界符 限定符
    面试官给我挖坑:rm删除文件之后,空间就被释放了吗?
    为什么 IPv6 难以取代 IPv4
    Docker系列教程04-Docker构建镜像的三种方式
    Docker系列教程03-Docker私有仓库搭建(registry)
    Linux-I/O模型详解
  • 原文地址:https://www.cnblogs.com/caobojia/p/5987692.html
Copyright © 2020-2023  润新知