简体   繁体   中英

preventing multiple user login for same user in java

I am using java with struts2 framework .and sqlserver 2005 database . i need help in preventing multiple user login with same username. i tried using session .. m new to this framework . if any one could help me it will be great . i did by using a flag in database and setting it to true .. and while logout it will be set to false .. but the problem i got is when some user accidently close the browser or some other interrupt happens .. the user will not be able to log in ...m totally confused wat method should i use ..i dint use any session or cookies .. if there s any simple method is there pls help me out of this ..

Maintain application map with logged in user. if any user try to create different session with the same userid invalidate her session.

Spring Security可以轻松地处理此问题,也许您可​​以尝试一下。

i think you can start one thread this update current time stamp in user master table after some time interval

if same user login from different browser you can check user master table timestamp and current server time gap more than interval

if not don't allow user to login

I think you should be using Sessions for such cases.

Accessing DB is an overhead.

This is a good tutorial to start with Session Management.

i did by using a flag in database and setting it to true .. and while logout it will be set to false

This is not the way sessions should be handled. Use cookies or other proper session handling techniques.

http://www.roseindia.net/struts/struts2/struts2-login.shtml

Tutorials are available!

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