![](/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.