package com.llf.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
/*
* 攔截器demo
*/
public class TextInterceptor implements HandlerInterceptor{
@Override
//最后執(zhí)行卫键,當(dāng)preHandle方法返回為true的時候才會執(zhí)行
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
// TODO Auto-generated method stub
System.out.println("afterCompletion方法");
}
@Override
//controller執(zhí)行完之后執(zhí)行傀履,當(dāng)preHandle方法返回為true的時候才會執(zhí)行
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView mav) throws Exception {
// TODO Auto-generated method stub
String s = "攔截器postHandel方法";
mav.addObject("s", s);
mav.setViewName("index");
}
@Override
//在controller方法執(zhí)行完之前才會執(zhí)行
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2) throws Exception {
// TODO Auto-generated method stub
// 登陸功能驗(yàn)證
// System.out.println("preHandle方法");
// int i = 2;
// if(i == 1){
// return true;
// }else{
// request.getRequestDispatcher("/jsp/login.jsp").forward(request, response);
// return false;
// }
return true;
}
}
spring-mvc.xml