首先,我们需要使得
ConcurrentSessionFilter 生效并在
spring-security.xml 配置。
<http auto-config="true" use-expressions="true">
<!-- Uncomment to limit the number of sessions a user can have -->
<session-management invalid-session-url="/index.do">
<concurrency-control max-sessions="1"
error-if-maximum-exceeded="false"/>
</session-management>
</http>其次,需要在
web.xml 描述文件中配置中使得
o.s.s.web.session.HttpSessionEventPublisher 生效,这样
servelt 容器将会通知
Spring Security session 生命周期的事件(通过
HttpSessionEventPublisher )。
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>

本文介绍了如何在Spring Security3中统计在线用户。通过配置`<session-management>`和`HttpSessionEventPublisher`监听器,结合`SessionRegistry`进行会话注册跟踪,实现了展示系统当前活跃用户数的功能。在Spring MVC JSP页面中,可以显示这个统计信息,为用户提供直观的在线用户数量展示。
最低0.47元/天 解锁文章
1464

被折叠的 条评论
为什么被折叠?



