Spring MVC 3 Global Request Mapping
I am trying to check whether the users have a cookie stored in their browser. If they do and the session is not set then call a service to log them in and set session. So the mapping scope has to be global because the users can bookmark any of the page and go back to it later.
So I was thinking of making a global controller like so
@RequestMapping("/*", method=REQUESTMETHOD.GET)
function(){login and set session if true}
..Unfortunately the /* doesn't seem to work with Spring MVC 3.
Of course, I can开发者_StackOverflow中文版 always do the following
--Inside my header.jsp (this file will be included on every pages)
<jsp:useBean id="link" class = "Test.CLASSNAME" />
<%=link.getMETHOD() %>
However, that solution doesn't seem to be too elegant.
So, my questions are
Is there anyway to do @RequestMapping with global scope?
Is there a better way to handle my situation using Spring MVC 3?
Thank you :)
Sounds like you need an interceptor, not a controller. These "cut across" your controller mappings, allowing you to apply logic to all your requests.
See the Spring docs here and here for how to write these are wire them up.
精彩评论