Access all user sessions in Struts 2

I am building a struts 2 application with JPA. The user can enter the application several times. I want to

  • in order to be able to view your entire session in the grid and possibly highlight the current session and, if desired, the user can select a session and end it.
  • The administrator should also be able to see all registered users and also view all sessions of each registered user, and also, if necessary, end any sessions.

thank

+3
source share
1 answer

I think that HttpSessionBindingListeneris what you are looking for. I will not write down the complete code, just offer you a way you can do this:

() User class (DTO), sessions of users.

e.g private static Map<User, HttpSession> usersSessions= new HashMap<User, HttpSession>();

User class implemets HttpSessionBindingListener. valueBound(HttpSessionBindingEvent event), session usersSessions :

usersSessions.put(this, event.getSession());

valueUnbound(HttpSessionBindingEvent event) :

usersSessions.remove(this);, users session logout.

, Map active sessions , . IMO, .

+5

All Articles