Look into the org.springframework.web.servlet.HandlerInterceptor.

You can create a class that extends the HandlerInterceptorAdapter class and implements the preHandle(HttpServletRequest request,...