Content Application Developer Manual / Version 2406.1
Table Of Contents
Spring MVC includes a concept for preprocessing and post-processing a handler's execution. By
implementing a HandlerInterceptor
it is possible for example to modify the
ModelAndView
of all executed handlers.
Example:
import org.springframework.web.servlet.HandlerInterceptor; public class MyInterceptor implements HandlerInterceptor { ... void postHandle(HttpServletRequest req, HttpServletResponse res, Object handler, ModelAndView modelAndView) throws Exception { // adds a new model object to the model and view modelAndView.addObject("message", "Hello World"); } ... }
A custom interceptor can be associated with all handlers by adding the interceptor bean to a
global list bean named handlerInterceptors
that defined by the CAE framework. A
customizer might be used here, for example
<customize:append id="addMyInterceptor" bean="handlerInterceptors"> <list> <bean class="com.mycompany.MyInterceptor"/> </list> </customize:append>
See Spring Framework documentation for more information about handler interceptors.