首页 > 代码库 > spring拦截器

spring拦截器


<!--     将拦截所有请求 -->
<!--     <mvc:interceptors> -->
<!--         <bean class="com.SpringInter"></bean> -->
<!--     </mvc:interceptors> -->
    
    
<!--     针对具体路径进行拦截 -->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/test"/>
            <bean class="com.SpringInter"></bean>
        </mvc:interceptor>
    </mvc:interceptors>
package com;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class SpringInter implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        String url=request.getRequestURI();
        System.out.println(url);
        return true;
    }

    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {

    }

    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {

    }

}

 

spring拦截器