Session 注销时使JSF2中的Http会话无效
版本: ApacheMyFaces 2.1.14 RichFaces 4.3.5 问题: 我想在用户单击注销页面时使JSF会话无效。 我已决定使用Session 注销时使JSF2中的Http会话无效,session,jsf-2,Session,Jsf 2,版本: ApacheMyFaces 2.1.14 RichFaces 4.3.5 问题: 我想在用户单击注销页面时使JSF会话无效。 我已决定使用PreRenderViewEvent进行同样的操作。 以下是相同的设计: 呈现注销页面时,通过PreRenderViewEvent调用后端bean中的侦听器方法。 在java方法中使JSF会话无效,如:FacesContext.getCurrentInstance().getExternalContext().invalidateSession() 我
PreRenderViewEvent
进行同样的操作。
以下是相同的设计:
呈现注销页面时,通过PreRenderViewEvent
调用后端bean中的侦听器方法。
在java方法中使JSF会话无效,如:FacesContext.getCurrentInstance().getExternalContext().invalidateSession()代码>
我的问题是:这是使会话无效的正确方法吗?或者有没有更好的方法
代码:
<!-- call this in Logout.xhtml page -->
<f:event listener="#{bean.invalidateSession}" type="preRenderView" />
我通常只在模板中添加一个按钮:
<h:commandLink action="#{loginBean.logout()}" value="Logout" rendered="#{!empty loginBean.account}" />
这和他的代码是一样的
<h:commandLink action="#{loginBean.logout()}" value="Logout" rendered="#{!empty loginBean.account}" />
public String logout()
{
setAccount(null);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().clear();
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
NavigationUtils.redirect("/admin/login");
return "";
}