Springmvc中的处理器、拦截器、过滤器的执行时机
测试案例:
public class MyFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("--->> MyFilter.init");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("--->> MyFilter.doFilter");
chain.doFilter(request, response);
}
@Override
public void destroy() {
System.out.println("--->> MyFilter.destroy");
}
}
public class MyInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("--->> MyInterceptor preHandle");
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
System.out.println("--->> MyInterceptor postHandle");
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
System.out.println("--->> MyInterceptor afterCompletion");
}
}
public class MyListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("--->> MyListener.contextInitialized");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("--->> MyListener.contextDestroyed");
}
}
执行顺序:
标签:拦截器,Springmvc,System,---,Override,过滤器,println,public,out From: https://www.cnblogs.com/dongyaotou/p/18388432