Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:23:00+00:00 2026-06-17T15:23:00+00:00

I opened the session in my servlet when the user performed a successful login:

  • 0

I opened the session in my servlet when the user performed a successful login:

HttpSession session = request.getSession(true);
session.setAttribute("name", name);

then I wrote in the logout.jsp to terminate the session:

<%session.invalidate();%>

To check if a session is valid I am doing this:

HttpSession session = request.getSession();
String name = (String) session.getAttribute("name");

But it is not working, I am getting the session valid even after the session.invalidate.
Does anyone understand where am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:23:01+00:00Added an answer on June 17, 2026 at 3:23 pm

    you should call session.getSession(false) – which returns null if there is no current session.

    according to docs

    HttpSession#getSession(boolean create) – create – true to create a new session for this request if necessary; false to return null if there’s no current session.

    So the correct way of session value check would –

    HttpSession session = request.getSession(false);
    if(session!=null)
      session.setAttribute("name", name);
    

    and once you invalidate the session –

    HttpSession session = request.getSession(false);
    if(session!=null)
    session.invalidate();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I opened up Business Intelligence Design Studio (BIDS) the other day. Since then my
I am working on the project which uses NHibernate. I don't keep session opened.
I would like to have two windows opened while running a single GVim session.
When trying to get an Hibernate session opened, the part of the code that
Say that there is a couchdb session opened through nano on node.js var dbserv
I Opened/Created a new Word document dynamically on FormLoad using: using Word = Microsoft.Office.Interop.Word;
I opened *.htm file with Excel Application ( Microsoft.Office.Interop.Excel ). It was parsed excellent!
I opened up a huge Solution in VS2008. I has about a little over
I opened a files in vim using gf command.which opened a file that the
I opened the files using :e or gf (Esc mode) commands in vim. when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.