访问 Struts 2 中的所有用户会话 [英] Access all User Session in Struts 2

查看:20
本文介绍了访问 Struts 2 中的所有用户会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JPA 构建一个 struts 2 应用程序.用户可以多次登录应用程序.我想要

I am building a struts 2 application with JPA. A user can login into the application multiple times. I want

  1. 用户能够在网格中查看他的所有会话,并可能突出显示当前会话,并且用户可以选择一个会话并终止它.
  2. 管理员还应该能够查看所有登录用户,还可以查看每个登录用户的所有会话,还可以选择终止任何会话.

谢谢

推荐答案

我认为 HttpSessionBindingListener 就是你要找的.我不会写完整的代码,只是建议你一种方法:

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:

您可以将静态字段(地图)添加到您的 用户类 (DTO) 中,您将在其中存储所有活动的 用户会话.:

You can add a static field (Map) to your User class (DTO) where you will store all active sessions of users. :

例如私有静态MapusersSessions= new HashMap();

然后让User class实现HttpSessionBindingListener.这样,您可以指定 valueBound(HttpSessionBindingEvent event) 方法,您可以在其中获取实际创建的 session 并将其放入您的 usersSessions 中,如下所示:

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());

valueUnbound(HttpSessionBindingEvent event)方法中然后:

usersSessions.remove(this);logout 后删除 users session.

这样您就拥有了所有 活动会话Map 以及它属于哪个用户的信息.IMO,您可以通过此轻松找出您的其他问题.

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.

这篇关于访问 Struts 2 中的所有用户会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆