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

查看:108
本文介绍了访问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:

你可以添加一个静态字段(Map)到你的用户类(DTO)您将存储所有活跃的用户会话。 :

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

例如私有静态地图< User,HttpSession> usersSessions = new HashMap< User,HttpSession>();

然后make 用户类 implementsmets HttpSessionBindingListener 。这样你可以指定 valueBound(HttpSessionBindingEvent事件)方法,你可以在其中获取实际创建的 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事件)方法中:

usersSessions.remove(this); 在<$之后删除用户会话 C $ C>注销。

usersSessions.remove(this); to remove users session after logout.

这样你就拥有所有活动会话的地图 还有关于它所属的用户的信息。你可以通过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天全站免登陆