spring 3.1.0.m mvc 使用filter

filter 我在现工程中是准备用来记录用户请求详细信息。现在记录的是普通的mvc中使用filter

现在在是之前的spring mvc工程基础上添加的filter  有些包在之前就导入了


导包

偷懒了,spring 3.1.0.M 全导入,

web.xml



	springDemo
	
		index.html
		index.htm
		index.jsp
		default.html
		default.htm
		default.jsp
	

	
	
		org.springframework.web.context.ContextLoaderListener
	
	
		contextConfigLocation
		/WEB-INF/demo.xml
	

	
	
		springContent
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			/WEB-INF/demo.xml
		
	
	
		springContent
		*.do
	
	
	
	
		DelegatingFilterProxy
		org.springframework.web.filter.DelegatingFilterProxy
		
			targetBeanName
			
			filter_saveuserinfo
		
		
			targetFilterLifecycle
			true
		
	
	
	
		DelegatingFilterProxy
		/search.do
	


然后是spring容器配置文件demo.xml




	
	
		
			
				
				demo_index
				
				
				demo_index
			
		
	
	
	
	
	
	
	
	


然后是filter_saveuserinfo ,需要实现filter接口,

package com.netel.web;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class Filter_saveUserInfo implements Filter {

    /**
     * Default constructor. 
     */
    public Filter_saveUserInfo() {
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		System.out.println("进入filter");
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
	}

}

完事,发布,请求search.do进入filter...



你可能感兴趣的:(spring,spring3.1.0.M,spring,filter)