1. 程式人生 > >MVC自定義攔截器Intercepetor

MVC自定義攔截器Intercepetor

pan return http throw span implement bject tor lan

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyIntercpetor implements HandlerInterceptor {
//請求執行方法之前執行
    @Override
    public
boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("MyIntercpetor.preHandle()"); return true; } //執行方法之後執行 @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
throws Exception { System.out.println("MyIntercpetor.postHandle()"); } //最終執行的方法 @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { System.out.println(
"MyIntercpetor.afterCompletion()"); } }

MVC自定義攔截器Intercepetor