拦截器有三个方法:preHandle, postHandle, afterCompletion
***-servlet.xml
<bean name="/test" class="cn.javass.chapter5.web.controller.TestController"/> <bean id="handlerInterceptor1" class="cn.javass.chapter5.web.interceptor.HandlerInterceptor1"/> <bean id="handlerInterceptor2" class="cn.javass.chapter5.web.interceptor.HandlerInterceptor2"/> //是HandlerMapping接口的实现类 <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"> <property name="interceptors"> <list> <ref bean="handlerInterceptor1"/> <ref bean="handlerInterceptor2"/> </list> </property> </bean>
中断流程
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("===========HandlerInterceptor1 preHandle"); response.getWriter().print("break");//流程中断的话需要我们进行响应的处理 return false;//返回false表示流程中断 }
性能监控,登陆检测 具体细节不太清楚。