无法在jsp中销毁会话

时间:2014-04-18 09:16:34

标签: jsp session

我在我的退出页面中使用它:

session.invalidate();
response.sendRedirect("login.jsp");

然后在每个页面上检查会话是否正在设置

session.getAttribute("username");
HttpSession session1 = request.getSession(false);

if(session1== null )
{%>
    <jsp:forward page="login.jsp"/>
<% 
}
else
{%>
      load the content of the page

它成功退出... 但当我按下浏览器上的后退按钮时,它会回到页面...我是最后一次。 我错了,可以做些什么

3 个答案:

答案 0 :(得分:0)

你可以在jsp上尝试这个,直到登录后你才会显示:

<强>的javascript

<script>
    window.onload=function() {
        history.forward();
    }; // trick to force user to redirect to the next page

    window.onunload=function () {};
</script>

答案 1 :(得分:0)

it get logout successfully... 
but when i press the back button on the browser
it get back to the page... i was last on. Where i am wrong and what can be done

你没错。因为它是浏览器功能

<强> 1。如果您尝试执行任何操作。 (即)如果您尝试向服务器发送任何请求,则不允许您这样做。

要阻止返回last页面,您可以在登录页面上尝试Disable the back button

希望这会有所帮助!!

答案 2 :(得分:0)

你的标记概念是为了避免这种情况。

登录成功完成后,在创建会话时,创建一个令牌并将其附加到会话中。

String token = UUID.randomUUID().toString();

将其存储在会话中。

session.setAttribute("token", token);

Pass it as hidden input value of the form.

在注销时,只需从会话中删除令牌即可。并将其转发到注销页面。在每个页面检查令牌,如果没有令牌,则将其重定向到主页。

相关问题