Kill user session

I have 3 tabs. Home, tab1, tab2. When the user starts the application, he is redirected to the "Home" tab, and I create a new session using HttpSession session = request.getSession(); When a user views other tabs, I maintain a session using HttpSession session = request.getSession(false); Now, if the user goes to the "Home" tab, I want to destroy the previous session and start a new session. Please tell me how to do this?

+4
source share
4 answers

Replace the code behind the home tab with

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

This, however, is a bit of a weird approach. I would rather add an attribute to the session and then intercept its presence.

+12
source
+1
source

in jsp you can reset a session with

 session.invalidate(); 

after that give the user a new

+1
source

use session.invalidate () first; destroy the session

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

+1
source

Source: https://habr.com/ru/post/1344915/


All Articles