标签:pre hand boolean 就会 一个 pos auto sys 请求
一、首先写一个类实现HandlerInterceptor,
实现HandlerInterceptor中的方法。
将preHandler 的返回值写成true,若不该就不会执行后面请求的方法了。
package com.neuedu.interceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; public class Inteceptor1 implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // TODO Auto-generated method stub System.out.println("preHandle"); return true; } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { System.out.println("postHandle"); } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { System.out.println("afterCompletion"); } }
二、在SpringMVC的配置文件中,我的是SpringMVC.xml配置interceptor
使用<mvc>的标签
<mvc:interceptors>
<!--class中写拦截器的全类名-->
<bean class="com.neuedu.interceptor.Inteceptor1"></bean> </mvc:interceptors>
这样在请求后台的响应的时候就会经过拦截器,执行拦截器中的方法。
标签:pre hand boolean 就会 一个 pos auto sys 请求
原文地址:http://www.cnblogs.com/xuesheng/p/7425344.html