如何获得在线用户

如何获得在线用户

package SessionCounter;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import com.oztime.right.UserObject;

public class SessionCounter implements HttpSessionListener {

private static int activeSessions = 0;
private static Vector v= new Vector();
public void sessionCreated(HttpSessionEvent se) {
}


public static void createsession(HttpSessionEvent se ) {
UserObject user1 =(UserObject)se.getSession().getAttribute("UserObject");
if(v.contains(user1)==false){
v.add(user1);
activeSessions++;
System.out.println("===================用户名称=================="+user1.getName());
System.out.println("===================用户数量=================="+activeSessions);
}

}

public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
UserObject user2=(UserObject)se.getSession().getAttribute("UserObject");
if(v.contains(user2)==true){
v.remove(user2);
activeSessions--;
System.out.println("===================removed=================="+user2.getName());
}

}
public static void Destroysession(UserObject user) {
//System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
//UserObject user3=(UserObject)se.getSession().getAttribute("UserObject");
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+user.getName());
if(v.contains(user)==true){
v.removeElement(user);
activeSessions--;
System.out.println("====================================="+user.getName()+"---退出登录!!!");
}

}

 

public static int getActiveSessions() {
return activeSessions;

}

public static Vector getVector() {
return v;
}
}

在用户登陆后调用的


SessionCounter.createsession(new HttpSessionEvent(session));

SessionCounter.Destroysession(user); //注user 为用户实体

posted on 2006-08-08 22:07 穷鬼 阅读(89) 评论(0)   编辑   收藏

你可能感兴趣的:(如何获得在线用户)