当前位置: 技术问答>java相关
在线人数统计怎么做?
来源: 互联网 发布时间:2015-10-03
本文导语: jsp做一个,在线人数统计; 登陆后再线人数加一,退出后减一 | import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class SessionCounter implements HttpSessionListener { private static...
jsp做一个,在线人数统计;
登陆后再线人数加一,退出后减一
登陆后再线人数加一,退出后减一
|
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionCounter implements HttpSessionListener
{
private static int intSessionsCount = 0;
private static Vector vc = new Vector(10);
public void sessionCreated(HttpSessionEvent se)
{
HttpSession ss = se.getSession();
if(ss!=null)
{
vc.addElement(ss) ;
}
intSessionsCount++;
}
public void sessionDestroyed(HttpSessionEvent se)
{
HttpSession ss = se.getSession();
if(ss!=null)
{
vc.remove(ss);
}
if(intSessionsCount > 0) intSessionsCount--;
}
public static int getSessionsCount()
{
return intSessionsCount;
}
public static Vector getAllSessions()
{
return vc;
}
}
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionCounter implements HttpSessionListener
{
private static int intSessionsCount = 0;
private static Vector vc = new Vector(10);
public void sessionCreated(HttpSessionEvent se)
{
HttpSession ss = se.getSession();
if(ss!=null)
{
vc.addElement(ss) ;
}
intSessionsCount++;
}
public void sessionDestroyed(HttpSessionEvent se)
{
HttpSession ss = se.getSession();
if(ss!=null)
{
vc.remove(ss);
}
if(intSessionsCount > 0) intSessionsCount--;
}
public static int getSessionsCount()
{
return intSessionsCount;
}
public static Vector getAllSessions()
{
return vc;
}
}