For intercepting the request, and then filtered interception
Implement HandlerInterceptor Interface
Configuring interceptors
Package cn.zys.lanjieqi; Import the javax.servlet.http.HttpServletRequest; Import javax.servlet.http.HttpServletResponse; Import org.springframework.web.servlet.HandlerInterceptor; Import org.springframework.web.servlet.ModelAndView; public class MyZhujieqi the implements HandlerInterceptor from { // performed prior to the request processing method // if true execute a return next interceptor // if false is returned to the next is not @Override public Boolean the preHandle (the HttpServletRequest request, Response the HttpServletResponse, Object Handler) throws Exception { // the TODO Auto-Generated Stub Method System.out.println ( "pretreatment ~ ~" ); return to true ; } // performed after the request processing method @Override public void The postHandle (the HttpServletRequest Request, Response the HttpServletResponse, Object Handler, ModelAndView ModelAndView) throws Exception { // the TODO Auto-Generated Stub Method System.out.println ( "post-processing ~ ~" ); HandlerInterceptor from. Super .postHandle (Request, Response, Handler, ModelAndView); } // perform post-processing DispatcherServlet - - suitable to do some cleanup work @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { // TODO Auto-generated method stub HandlerInterceptor.super.afterCompletion(request, response, handler, ex); } }
Configuration mvc.xml
<! - configuration interceptor -> < MVC: interceptors > <! - the configuration of an interceptor -> < : MVC Interceptor > <! - / ** all sub-paths that path -> < MVC: Mapping path = "/ **" /> < the bean class = "cn.zys.lanjieqi.MyZhujieqi" > </ the bean > </ MVC: Interceptor > </ MVC: interceptors >