![](/img/trans.png)
[英]how to implement production ready login logout functionality in servlet jsp
[英]How implement the login and logout functionality by using play 1.2.7 java framework
我正在使用play 1.2.7創建登錄和注銷功能,當用戶登錄時,我將使用會話對象為他創建會話,我的問題是我完成注銷后將重定向到登錄頁面,但是當用戶單擊瀏覽器后按鈕,頁面將刷新,然后再次登錄
這是我登錄用戶時的代碼。
public static void login() throws Throwable {
Http.Cookie remember = request.cookies.get("rememberme");
if(remember != null) {
int firstIndex = remember.value.indexOf("-");
int lastIndex = remember.value.lastIndexOf("-");
if (lastIndex > firstIndex) {
String sign = remember.value.substring(0, firstIndex);
String restOfCookie = remember.value.substring(firstIndex + 1);
String username = remember.value.substring(firstIndex + 1, lastIndex);
String time = remember.value.substring(lastIndex + 1);
Date expirationDate = new Date(Long.parseLong(time)); // surround with try/catch?
Date now = new Date();
if (expirationDate == null || expirationDate.before(now)) {
logout();
}
if(Crypto.sign(restOfCookie).equals(sign)) {
session.put("username", username);
redirectToOriginalURL();
}
}
}
flash.keep("url");
render();
}
這是當用戶注銷時我的注銷代碼:
public static void logout() throws Throwable {
Security.invoke("onDisconnect");
session.clear();
response.removeCookie("rememberme");
Security.invoke("onDisconnected");
flash.success("secure.logout");
login();
}
請讓我免於此問題的解決方法。謝謝。
使用安全模塊是一種方法: http : //www.playframework.com/documentation/1.2/secure 。
僅供參考,以下模塊擴展了安全模塊並支持基於角色的授權:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.