Maintaining Spring flash attribute after redirect is fulfilled
spring, spring-mvc
Solution
Inside your `HandlerInterceptor`, you should do the following
FlashMap lastAttributes = RequestContextUtils.getInputFlashMap(request); // should hold the attributes from your last request
FlashMap forNextRequest = RequestContextUtils.getOutputFlashMap(request); // will hold the attributes for your next request
forNextRequest.putAll(lastAttributes);
Problem
I have a controller that sets some flash attributes and calls a redirect. I also have a before controller interceptor in place that will intercept the redirected URL and force another redirection. At this point my Flash attributes are removed as spring thinks that the redirection target has been fulfilled. I would like to maintain those attributes so that my second controller can have access to them after the second redirect. Any possible way of achieving that? Please not that I cannot change the first controller that initially populates them and I need those attributes to reach the second redirection controller.