I am building a struts 2 application with JPA. A user can login into the application multiple times. I want
Thanks
I think HttpSessionBindingListener is what are you looking for.
I won't write down the complete code, just suggest you a way you can do it:
You can add a static field (Map) to your User class (DTO) where you will store all active sessions of users. :
e.g private static Map<User, HttpSession> usersSessions= new HashMap<User, HttpSession>();
Then make User class implemets HttpSessionBindingListener. This way you can specify valueBound(HttpSessionBindingEvent event) method in which you can grab actually created session and put it into your usersSessions like this :
usersSessions.put(this, event.getSession());
In valueUnbound(HttpSessionBindingEvent event) method then :
usersSessions.remove(this); to remove users session after logout.
This way you have Map of all of your active sessions also with information to which user it belongs to. IMO you can figure out your other problems easily with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With