所以这就是问题所在.当用户退出我的网站时,他们仍然可以点击后退按钮并继续使用该网站.为了跟踪用户是否登录,我创建了一个会话属性"isActive".用户登录时该属性设置为true,并且在注销时会话无效之前(冗余)删除该属性.同样在每个页面上,我都会检查属性是否存在.
我还指定不应在其head标签中缓存页面.
尽管如此,用户仍然能够回击浏览器,并继续使用该网站,就好像他们从未注销过一样.
有关如何解决此问题的任何想法?
这是代码:
登录Servlet:
...
session.setAttribute("isActive", true);
//Redirect to home page.
Run Code Online (Sandbox Code Playgroud)
检查登录的JSP:
<c:if test='${empty sessionScope.isActive || sessionScope.isActive != true}'>
<c:redirect url="/index.jsp?message=Session Timed Out."/>
</c:if>
Run Code Online (Sandbox Code Playgroud)
注销Servlet:
request.getSession().removeAttribute("isActive");
request.getSession().invalidate();
response.sendRedirect("index.jsp");
Run Code Online (Sandbox Code Playgroud)
内部标记:
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
Run Code Online (Sandbox Code Playgroud)
谢谢
在我的JSF应用程序中,我得到了这样的当前登录用户的名字......
public String getLoggedInUsername() {
return FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
}
Run Code Online (Sandbox Code Playgroud)
...我检查用户是否像这样登录...
public boolean isSignedIn() {
return (getLoggedInUsername() != null);
}
Run Code Online (Sandbox Code Playgroud)
......当用户退出时,我这样做......
public String doLogout() {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession httpSession = (HttpSession)facesContext.getExternalContext().getSession(false);
httpSession.invalidate();
return "main";
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在doLogout()之后,getLoggedInUsername()仍然返回登录用户的名称.我应该做些什么来确保getRemoteUser()在注销后返回null?
或者,是否有更好的方法来获取isSignedIn()而不仅仅是检查用户名?
谢谢!抢