如何在spring Framework中设置会话

如何在spring Framework中设置会话,spring,servlets,Spring,Servlets,现在我有了这样的登录代码,UserInfo是一个带有用户名和密码的表单 @RequestMapping(value = "/login/loginCheck", method = RequestMethod.POST) public Map<String, Object> loginCheck(UserInfo userInfo) @RequestMapping(value = "/login/PageA", method = RequestMethod.POST) public

现在我有了这样的登录代码,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 
}
@RequestMapping(value=“/login/loginCheck”,method=RequestMethod.POST)
公共地图登录检查(用户信息用户信息)
@RequestMapping(value=“/login/PageA”,method=RequestMethod.POST)
公共地图第a页(){
//也许可以检查一下会议
//如果会话过期,则重定向到登录页面
}
登录后,我应该将页面重定向到页面A,并在会话中记录用户名,所以在spring框架中,我是配置它还是从请求中获取会话


希望澄清

有很多方法,一种是简单地将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 
}
@RequestMapping(value=“/login/PageA”,method=RequestMethod.POST)
公共地图页面A(HttpSession HttpSession){
//也许可以检查一下会议
//如果会话过期,则重定向到登录页面
}
如果会话不再有效,HttpSession的
getAttribute
方法将抛出IllegalStateException,但我感觉Spring MVC会在这种情况下为您创建一个新会话,所以还要检查不存在(空值)

还可以查看Spring文档上的
@SessionAttributes
@modeldattribute
注释以及Spring安全框架的用法