I have an interceptor which extends the HandlerInterceptorAdapter.
When I add an object to my ModelAndView it also gets added to my url as a path variable but I don’t want that.
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
if (null == modelAndView) {
return;
}
log.info("Language in postHandle: {}", LocaleContextHolder.getLocale());
modelAndView.addObject("selectedLocale", LocaleContextHolder.getLocale());
}
When I add something to my ModelAndView in the controller itself, it doesn’t appear in the url.
My suspicion is that the controller has returned a redirect view. When you add attributes to the model used by
RedirectView, Spring will tack the attributes on to the URL.Try looking inside the
ModelAndViewobject to see if the view is aRedirectView, and if so, then don’t add the locale attribute.