在我的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()而不仅仅是检查用户名?
谢谢!抢
Bal*_*usC 16
确保在使会话无效后重定向请求.基于会话属性解析用户主体.因此,当您转发到目标页面时(默认情况下作为JSF导航案例),它仍然会在目标页面中,因为它使用相同的 HttpSession
引用.重定向指示webbrowser触发全新的HTTP请求,从而强制服务器HttpSession
根据新请求重新创建引用.
添加<redirect/>
到导航案例以强制JSF发送重定向.或者当您已经使用JSF 2.0时,添加?faces-redirect=true
到结果值.