问题
Can we access "spring_security_last_username" form the Controller instead of jsp?
回答1:
SPRING_SECURITY_LAST_USERNAME is a session attribute, therefore you can access it from the controller like any session attribute:
public ModelAndView controller(..., Session s) {
String lastUsername = s.getAttribute("SPRING_SECURITY_LAST_USERNAME");
...
}
回答2:
I just want to add that the SPRING_SECURITY_LAST_USERNAME_KEY is deprecated. As mentioned in its deprecation note, you should use your custom failureHandler to retain any user information.
来源:https://stackoverflow.com/questions/5537252/spring-security-last-username