你的問題直接與瀏覽器有關,所以你需要告訴瀏覽器每次註銷時都要從你的頁面「重新啓動」緩存,爲了讓它認爲這是第一次客戶端正試圖進入該頁面。與Chrome和Firefox中的私人窗口一樣。
試試這個代碼:
//...
response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility
//can check userId or something likes this.In this sample, i checked with userName.
String userName = (String) session.getAttribute("User");
if (null == userName) {
request.setAttribute("Error", "Session has ended. Please login.");
RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
rd.forward(request, response);
}
來源:How to clear browser cache using java
謝謝。這可以用FacesContext來完成嗎? –
在java(或任何其他語言和/或容器恕我直言)的服務器端沒有辦法強制這一點。我做了大量的研究,唯一可靠的方法是重新啓動瀏覽器。 – mvreijn