0

现在我有一个这样的登录代码,UserInfo 是一个带有用户名和密码的表单

@RequestMapping(value = "/login/loginCheck", method = RequestMethod.POST)
public Map<String, Object> loginCheck(UserInfo userInfo)

@RequestMapping(value = "/login/PageA", method = RequestMethod.POST)
public Map<String, Object> PageA(){
   //maybe check the session
   //if session expired ,then redirect to login page 
}

登录后,我应该将页面重定向到页面A,并在会话中记录用户名,那么在spring框架中,我只是配置它还是从请求中获取会话?

希望清楚。

4

1 回答 1

0

有很多方法,一种是简单地将 HttpSession 注入到你的处理程序方法中

@RequestMapping(value = "/login/PageA", method = RequestMethod.POST)
public Map<String, Object> PageA(HttpSession httpSession){
   //maybe check the session
   //if session expired ,then redirect to login page 
}

getAttribute如果会话不再有效,HttpSession的方法将抛出 IllegalStateException,但我感觉 Spring MVC 会在发生这种情况时为您创建一个新会话,因此还要检查是否不存在(空值)

还可以查看Spring doc 和 Spring Security 框架的用法@SessionAttributes和注释@ModelAttribute

于 2013-07-15T04:39:58.650 回答