[英]session invalidate in JSF2.0
我正在使用JSF2.0和jsp 。我試圖在我的項目中加入會話失效。我嘗試使用以下代碼。
<h:commandButton value="Logout" action="#{bean.logout}" </h:commandButton>
我的bean類包含以下方法
public class Bean{
public String logout(){
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)context.getExternalContext().getSession(false);
session.invalidate();
return "login";
}
}
其中string login重定向到登錄頁面。
我的項目有幾個頁面,其中包括一個標題頁..當我嘗試上述方式... 當我從第一頁點擊退出時工作正常...如果我去其他頁面后嘗試相同,它的沒有退出 。任何人都可以幫助我...這是我們在這里使會話無效的方式???
UPDATE
我也嘗試在導航規則中使用“*”,以便每個頁面都可以重定向到Login ...但問題仍然是相同的
嘗試
return "login?faces-redirect=true"
作為結果,瀏覽器不會對登錄頁面使用相同的請求,該會話仍然處於活動狀態。
你試過這個 -
return "/login?faces-redirect=true";
如果視圖登錄位於根目錄中。
否則,如果它在其他文件夾中,則如下 -
//if it's in the folder - folder1
return "/folder1/login?faces-redirect=true"
注意/
在結果的開頭。
使用remoteCommand
標簽並在注銷時使用JavaScript調用此remoteCommand
並在managedBean
提供用於注銷的實現, managedBean
可以在此處粘貼,只需要enter code here
以重定向到登錄頁面,或者您可以再次使用JavaScript重定向到登錄頁。
<h:commandButton value="Logout" onclick="closeSession();" </h:commandButton>
<p:remoteCommand name="closeSession"
action="#{jobController.logout}">
public class Bean{
public String logout(){
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)context.getExternalContext().getSession(false);
session.invalidate();
return "login?faces-redirect=true";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.