I am trying to set a global title for my webpage inside Sring MVC Interceptor posthandle method like so
Interceptor Class
model.addObject("title", "global title"); //ModelAndView
T开发者_JAVA百科hen in my controller class I have
model.addAttribute("title", "Specific page title"); //Model - Overwrite global title
my jsp header
<title>${titile}</title>
The problem is that I always get the "global title" as a value for the title variable. For some reason, the model ui inside the controller never overwrote the one that being set inside the interceptor.
If I understand correctly, you implement HandlerInterceptor.postHandle()
method. PostHandle means, this is run after the individual controller has been run. Since you are setting the title attribute after the individual handler has tun to "global title", you will always get "global title".
Try HandlerInterceptor.preHandle() - there is a chance this would work better I think...
(EDIT: typed nonsense... try preHandle(), not try postHandle())
精彩评论