简体   繁体   中英

Tomcat java servlet - how to track users that are logged in?

I am going to create a simple player versus player servlet-based browser game and deploy it in tomcat, and I need to be able to know at any given point in time which users are connected. Each user will have his own account (username, password, role) that will be stored in a mysql database (using a jdbc realm). What I want to do is to somehow track all users by having a database table where usernames of logged on users are stored.

The only problem is how do I know when someone logs in or out.

Edit: I saw someone recommending a HttpSessionBindingListener in another post. However, I have not got the slightest idea on how to implement this

A good way to track this is to log all the events , user login and user logout, and store this with a time stamp. This makes it much easier to implement timeout and other features.

you can use log4j framework for your project logging. you can find implementation at this site http://www.tutorialspoint.com/log4j/log4j_sample_program.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM