You can use an interceptor for this. The order of events for request processing in Spring MVC:
- DispatcherServlet receives a pair of Request, Response and defines processing
- [optional] called preHandle interceptors (with the possibility of stopping processing)
- the controller is called
- [optional] called postHandle interceptors
- ViewResolver and view do the actual processing of the response and send the response
- [optional] called afterCompletion interceptors
afterCompletion
too afterCompletion
and is intended only to show that the afterCompletion
methods after sending a response to the client with the following signature:
void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception
In this method, you can check for an exception and the correct response ( ex == null && response.getStatus() == HttpServletResponse.SC_OK
) before starting the processing.
source share