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 8475153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:49:06+00:00 2026-06-10T17:49:06+00:00

When a user logs in to my web app, I create a session: session.setAttribute(SessionNumber,100);

  • 0

When a user logs in to my web app, I create a session:

session.setAttribute("SessionNumber","100");

And his username is added to a table named ONLINE_USERS.
Other Online users will be able to see him, they see all online users

When the user clicks on the log out button, I delete that row from the table, then I delete the session using:

session.invalidate();

But let’s say the user existed the browser, his session will be gone, but the row will stay in the database as an online user, how to avoid this?

I’m using JSP-Servlets on Netbeans.

  • 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-10T17:49:07+00:00Added an answer on June 10, 2026 at 5:49 pm

    You can enable a custom HttpSessionListener to delete the table row upon session invalidation.

    public class YourHttpSessionListener implements HttpSessionListener {       
       public void sessionCreated(HttpSessionEvent event) {
       //put row in the database
       }
    
       public void sessionDestroyed(HttpSessionEvent event) {
         //delete the row from database     
       }
    }
    

    Declare the listener in your web.xml:

    <listener>
        <listener-class>YourHttpSessionListener</listener-class>
    </listener>
    

    Note that there will be a delay between the moment the user exits the browser and his session expires on the server. But session expiration time is configurable. You should find a suitable expiration timeout: not too long so you don’t display for too much offline users as online, but not too short to allow connected users an idle period.

    I think this is a good trade off for a chat application developed with basic servlet and jsp technology.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my web app, when a user logs in, I add his Id to
In my web app after a user logs in a new session is created
When a user logs in with his UserName , I send the UserName to
When a low-privilege non-administrator user logs into my web app successfully, I am storing
My process is as follows: User logs into web app and this drops an
When a user logs in to a Windows Active Directory environment, his/her password is
I have a facebook app and a user logs in and uses it. Simple.
In my PHP Web-App I use sessions to store the user's data. For exmaple,
My web app runs well except one thing. File Uplods. Basically when a user
So I've made a web app that among other, allows administrators to change user

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.