close

Filter

loading table of contents...

Content Application Developer Manual / Version 2101

Table Of Contents

4.3.1.2 Post Processing the Model

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 http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-handlermapping for more information about handler interceptors.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.