原文摘自:http://www.hudixin.net/?p=47
很多現在都在困擾 ss3 如何記錄使用者的登入時間
其實很簡單下面我就一步一步告訴你們
找到 security 的配置檔案,在xml檔案中 找到 http 下的 form-login 添加一個屬性 authentication-success-handler-ref
如示:
<form-login login-page="/login.do"
authentication-success-handler-ref="loginSuccessHandler"
authentication-failure-handler-ref="loginFailureHandler"
authentication-failure-url="/login.do?login_error=1"
always-use-default-target="true" default-target-url="/index.do" />
再 自己寫個類loginSuccessHandler 實作 AuthenticationSuccessHandler 接口
如示:
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws ServletException, IOException {
//這裡填寫自己要執行的操作 如使用者的登入時間、ip等等。
}
這樣就可以啦。。。簡單吧~~!