2013-07-15 36 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框架