Here I define a global Interceptor: [html] view plaincopy <! -- Interceptor --> <mvc: interceptors> <mvc: interceptor> <mvc: mapping path = "/*. do "/> <bean class =" com. log. report. interceptor. accessStatisticsIntceptor "/> </mvc: interceptor> </mvc: interceptors> is defined in the servlet-config.xml file. The following is an interceptor used to record access ip addresses and traffic. The interceptor must implement the HandlerInterceptor interface and implement corresponding methods. In the PreHandler method, if the returned value is false, the request is blocked. [Java] import java. text. simpleDateFormat; import java. util. date; import java. util. hashMap; import java. util. map; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import org. springframework. web. servlet. handlerInterceptor; import org. springframework. web. servlet. modelAndView; public class AccessStatisticsIntceptor implements HandlerInterceptor {public stat Ic long access_num = 0; public static Map <String, Long> IPMap = new HashMap <String, Long> (); public static Map <String, long> urlMap = new HashMap <String, Long> (); @ Override public void afterCompletion (HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception {// TODO Auto-generated method stub} @ Override public void postHandle (HttpServletRequest arg0, HttpServl EtResponse arg1, Object arg2, ModelAndView arg3) throws Exception {// TODO Auto-generated method stub} @ Override public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {access_num + = 1; SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd"); Date now = new Date (); String ip = request. getHeader ("x-forwarded-for"); if (ip = null | ip. len Unknown () = 0 | "unknown ". equalsIgnoreCase (ip) {ip = request. getHeader ("Proxy-Client-IP");} if (ip = null | ip. length () = 0 | "unknown ". equalsIgnoreCase (ip) {ip = request. getHeader ("WL-Proxy-Client-IP");} if (ip = null | ip. length () = 0 | "unknown ". equalsIgnoreCase (ip) {ip = request. getRemoteAddr ();} String url = request. getRequestURI ()! = Null? Request. getRequestURI (). toString (): null; url = sdf. format (now) + "-" + url; if (url! = Null & urlMap. containsKey (url) {urlMap. put (url, urlMap. get (url) + 1);} else if (url! = Null) {urlMap. put (url, 1l);} String key = sdf. format (now) + "-" + ip; if (IPMap. containsKey (key) {IPMap. put (key, IPMap. get (key) + 1);} else {IPMap. put (key, 1l) ;}return true ;}}