zoukankan      html  css  js  c++  java
  • 自定义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. }  
     
  • 相关阅读:
    Spring3.2新注解@ControllerAdvice
    Spring读取加密属性文件处理--待整理
    SpringMVC之三:配置Spring MVC Controller
    深入理解DIP、IoC、DI以及IoC容器
    缓存与数据库一致性之三:缓存穿透、缓存雪崩、key重建方案
    Spring容器初始化过程
    Spring框架中的@Import、@ImportResource注解
    @SpringBootApplication注解分析
    Spring bean加载之1:BeanFactory和FactoryBean
    内存使用情况
  • 原文地址:https://www.cnblogs.com/caobojia/p/5987692.html
Copyright © 2011-2022 走看看