Hi how to know which users are inactive ( have not opened a page or did not do anything in a particular time), I am using jsp and java.
-
possible duplicate of [How to expire session due to inactivity in Django?](http://stackoverflow.com/questions/3024153/how-to-expire-session-due-to-inactivity-in-django) - not exact duplicate, but the idea and answer is the same. – nothrow Oct 06 '12 at 13:48
3 Answers
I'm assuming you want to have knowledge about inactive users from the server's point of view. If you just want a client-side solution, the other answers will steer you in the right direction.
Anyhow, there's no general way to get this knowledge on the server-side, unless you track the information yourself. Your web container probably maintains persistent sessions using cookies that expire after some interval, but if you want to map back from a particular session to a user (or from a user to a session) then you need to maintain that mapping yourself in your database.
So you could add some code to correlate a user with a session and track a last-seen timestamp against each user, and then you could easily determine which users are inactive, and take whatever action it is that you want to take.
Of course, if you don't care about knowing specifically which users are inactive and you just want to ensure that all users who have been inactive for more than x
minutes lose their session, you can do that by configuring your web container's session expiry time. The process for doing so will depend upon which particular server you are running.

- 54,026
- 20
- 135
- 176
You can apply a javascript to set a interval for checking the activity of the user. Then you will know if the user is still on the page.
setInterval(function(){ update(); },3000); // Send a update every 3 seconds
The update()
can be a AJAX POST to indicate which page the user is watching and how long the user has been staying.

- 771
- 11
- 28
You can use javascript to track idle time elegantly
Check this out handle idle time in javascript

- 1
- 1

- 8,387
- 6
- 37
- 77