• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

URGENT: Sessions in JSP

Hi,
   I'm a brazilian man.
   Doubt in JSP:
   Suppose that I have a database with many users registereds...
   How I do for know if a user (registered and logged in yet) is online in the moment that other user search for someone in my database?
   Update a field (as "isOnline=yes") in database, after login, is a solution, but how to update the field (for "isOnline=no", by example) when the user session to expires?
   I hope you help me.
   Sorry my bad english!!!
I'm waiting...
0
marciodorimar2
Asked:
marciodorimar2
2 Solutions
 
kennethxuCommented:
You are mostly correct. but I think you should use a counter instead of yes/no. because one user can have multiple session. and you also need to handle user login into same session multiple times.

Another implmentation will be use session listener to track sessions. run a timer to build/update active user table from data in active sessions
0
 
Binary1Commented:
It is difficult to tell from a web session if someone is still active or not. This presents a lot of problems with this type of thing.

You can track within the database the last time the user interacted with the system. After a certain, predefined period the user would be considered logged out. Problems with this approach are that this would need to coordinated with the actual user log in and each interaction from the user would need to update this information.

A second way would be to use a java Bean to maintain a list of "active" users. The bean would need to have application scope so it is available to all users. The method described above could be used and made simpler if the user log in was also managed by this Bean. You could maintain the user list within something like a Vector or HashTable that would then be looked up by the application.


You could also create a Java Bean that would update the database with the logged in status and use the "finalize()" method to update the status to not logged in. The problem with relying on this is you are at the mercy of the Java garbage collection to call the finalize() to flag a user as no longer active. This may not occur for a long time after the user is no longer using the system.


The simplest and quickest way would be to track when the user connected and determine a default "logged out" period to determine whether they are on-line or not.
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between kennethxu and Binary1

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now