2013-07-15 31 views
0

我有这样一个登录码的UserInfo是用户名和密码如何在春季framewok设置会话现在

@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,并记录用户名中会话,所以在春季框架中,我只是配置它或从请求中获取Session?

希望清楚。

回答

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 
} 

的HttpSession的getAttribute方法会抛出IllegalStateException异常,如果会话不再有效,但我有一种感觉,Spring MVC的将创建你一个新的会话时发生,因此也检查不存在(空值)

也有看的@SessionAttributes@ModelAttribute注释春文档的使用和Spring Security框架