统计在线用户并进行监控
2011-03-10 17:42
239 查看
一、在线用户数据表
二、当用户登录时
将用户的数据放入数据库中(代码略)
因为在sessionCreated()方法中,取出的用户信息为空,直接在这一步中直接将用户保存到数据库中。
三、当用户登出时,
1,在action中调用
getSession().invalidate();
2,session监听就会启动。
在sessionDestroyed()方法中,他会删除用户的信息。
例如:
在上面的例子中:可以直接取Spring中的实体Bean.
WebApplicationContext ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(session.getServletContext());
3,要使HttpSessionListener启作业,还需要在wex.xml中配置
这样就完工了
create table CRM_SESSION ( USERID NUMBER, USERNAME VARCHAR2(50), SESSIONIDS VARCHAR2(50), USERSTATE VARCHAR2(50), CALLSTATE VARCHAR2(50) ); alter table CRM_SESSION add constraint AK_KEY_1_CRM_SESS unique (USERID)
二、当用户登录时
将用户的数据放入数据库中(代码略)
因为在sessionCreated()方法中,取出的用户信息为空,直接在这一步中直接将用户保存到数据库中。
三、当用户登出时,
1,在action中调用
getSession().invalidate();
2,session监听就会启动。
在sessionDestroyed()方法中,他会删除用户的信息。
例如:
package cn.com.xinli.crm.core; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import cn.com.xinli.crm.ibatis.commquery.SessionID; import cn.com.xinli.crm.ibatis.sysmanage.SysUser; import cn.com.xinli.crm.service.commquery.ISessionIDService; public class UserOnline implements HttpSessionListener { public void sessionCreated(HttpSessionEvent event) { } public void sessionDestroyed(HttpSessionEvent event) { try { HttpSession session = event.getSession(); SysUser user = (SysUser) session.getAttribute("sessionUser"); WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(session .getServletContext()); ISessionIDService sesService = (ISessionIDService) ctx .getBean("sesService"); SessionID sid = new SessionID(); sid.setUserid("" + user.getUserId()); sesService.del(sid); } catch (Exception e) { e.printStackTrace(); } } }
在上面的例子中:可以直接取Spring中的实体Bean.
WebApplicationContext ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(session.getServletContext());
3,要使HttpSessionListener启作业,还需要在wex.xml中配置
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>CampusCRM</display-name> <!-- struts2配置 --> <filter> <filter-name>Struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>Struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <session-config> <session-timeout>300</session-timeout> </session-config> <!--Spring相关配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml </param-value> </context-param> <!-- spring 配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>cn.com.xinli.crm.core.UserOnline</listener-class> </listener> <!--配置定时任务 --> <servlet> <display-name>Quartz Initializer Servlet</display-name> <servlet-name>QuartzInitializer</servlet-name> <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
这样就完工了
相关文章推荐
- 在线用户监控
- 使用HttpSessionListener接口实现用户在线状态监控
- 分享一个帮助你查看用户访问流程的在线统计工具 - Flow
- Sap NetWeaver CE7.1如何统计在线用户
- java中监控在线用户
- NAGIOS脚本统计在线用户mongoDB
- 让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能
- java通过监听Session实现统计在线用户
- 在线用户统计二
- ASP.NET中在线用户统计
- 在线用户统计的实现方法
- jsp中基于session的在线用户统计分析
- WhoIsOnline ;) - 解读CNForum源码中在线用户统计
- Jsp在线人数统计 - 实现后台强制前台某个用户退出
- HttpSessionListener实现对在线用户的精确统计
- java简单的在线用户统计
- Spring Boot使用Druid进行维度的统计和监控
- asp.net 在线用户列表统计
- [总结]关于在线用户列表的统计!
- 实现统计在线用户的几种方式