Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill user session

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?

like image 654
dazzle Avatar asked Dec 06 '22 22:12

dazzle


2 Answers

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.

like image 61
BalusC Avatar answered Dec 10 '22 12:12

BalusC


You could use session.invalidate()

like image 23
sdorra Avatar answered Dec 10 '22 13:12

sdorra