Kill user session

馋奶兔 提交于 2020-01-01 05:51:09

问题


I have 3 tabs. Home, tab1, tab2. When user launches the app, its directed to Home tab & I create a new session using HttpSession session = request.getSession(); When user browses to other tabs, I maintain the session using HttpSession session = request.getSession(false); Now if the user click back on Home tab, I want to destroy the previous session and start fresh with new session. Please tell me how to do it?


回答1:


Replace the code behind home tab by

HttpSession session = request.getSession();

if (!session.isNew()) {
    session.invalidate();
    session = request.getSession();
}

This is however a bit odd approach. I would rather put an attribute in the session and then intercept on its presence instead.




回答2:


You could use session.invalidate()




回答3:


in jsp you can reset the session with

session.invalidate();

after that give the user a new one




回答4:


first use session.invalidate(); to destroy session

request.getSession(true); will create new session if there is no session



来源:https://stackoverflow.com/questions/5404907/kill-user-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!