web.xml和Filter的对应关系

1.在SSM中的web.xml和Filter的对应关系

package com.qingfeng.filter;

public class UserFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    	System.out.println("进入了init方法。。。。。。" );
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("进入了doFilter方法。。。。。。" );
    }
    @Override
    public void destroy() {
 System.out.println("进入了destroy方法。。。。。。" );
    }
}

2. 过滤器

<!-- 配置过滤器 -->
	<filter>
		<filter-name>UserFilter</filter-name>
		<filter-class>cn.tedu.store.filter. UserFilter </filter-class>
          <!--  给对象属性赋值-->
          <init-param>
			<param-name>serverName1</param-name>
			<param-value>http://localhost:8080</param-value>
		</init-param>
		<init-param>
			<param-name>serverName2</param-name>
			<param-value>http://localhost:8082</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>UserFilter</filter-name>
          <!--这里使用*.do的请求才能filter过滤,允许访问,没有以.do结尾的都要被拦截,不被访问-->
		<url-pattern>*.do</url-pattern>
	</filter-mapping>

  

3.web.xml和Filter的对应关系

猜你喜欢

转载自www.cnblogs.com/Amywangqing/p/12896683.html