Kill user session

2020-06-23 07:44发布

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?

4条回答
Animai°情兽
2楼-- · 2020-06-23 08:00

in jsp you can reset the session with

session.invalidate();

after that give the user a new one

查看更多
萌系小妹纸
3楼-- · 2020-06-23 08:08

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.

查看更多
SAY GOODBYE
4楼-- · 2020-06-23 08:15

first use session.invalidate(); to destroy session

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

查看更多
5楼-- · 2020-06-23 08:19
登录 后发表回答