簡體   English   中英

在后退按鈕上單擊注銷后重新加載jsp頁面

[英]reload jsp page after logout on back button click

在我的每一頁中,都有一個注銷選項。 當用戶單擊此注銷選項時,他們將注銷session.invalidate(); 當我按下后退按鈕時,即使會話無效,我也會獲得上一頁包含輸入標簽中所有內容的頁面。如何解決此問題。我嘗試了window.location.reload()和許多其他選項,但無法在此處使用。\\ 我的網站是這個。 和憑據。 test123@gmail.com並通過是Amal123

僅在會話處於活動狀態時,要打開所有頁面之前,您必須放置一個過濾器,以在打開頁面之前檢查會話。

在登錄時,您必須使當前會話無效。

然后您將可以按返回按鈕,但不能執行任何功能

您可以使用會話屬性...例如,當您登錄時,將變量值設置為用戶名,例如:HTML

<form name="login" action="/login.jsp" method="post" >
    <input type="text" name="username" >
    <input type="password" name="password" >
<input type="submit" >

JSP:

String userName=request.getParameter("username");
request.getSession().setAttribute("username",userName);

現在在每個頁面上添加此代碼

<% if(request.getSession().getAttribute("username")==null) response.sendRedirect("index.jsp");%>

同樣,在注銷時不要忘記刪除會話屬性。

request.getSession().removeAttribute("username");

試試看,讓我知道。

您可以將此代碼復制並粘貼到網站的每個頁面中,以清除緩存的頁面。

 <%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);

if(session.getAttribute("some_token")==null)
  response.sendRedirect("login/login.html");

%> 

在注銷中,您必須使會話無效,因此,當您單擊返回時,它將檢查sessionsome_token屬性值,如果不存在,則會將您重定向到login頁面。 但是請記住,登錄后要在會話中設置some_token屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM