去这里看看
http://www.javaresearch.org/article/showarticle.jsp?column=2&thread=406
http://www.javaresearch.org/article/showarticle.jsp?column=2&thread=406
解决方案 »
- frame 自适应高度
- 关于jsp中的request.getInputStream()上传文件的问题
- jsp选修课系统中限制选课门数。。。。。
- 发个Java技术交流群
- HelloWorld.java:1: package Java.io does not exist
- 就只有几行代码呀,为什么tomcat中显示一大堆看不懂的错误呀,请问我那里错了?在线等,解决就解贴,谢谢
- 得到总数量,为什么是空?
- 在jbuild8下的写jsp,怎么不能用菜单Edit中的Format Line?
- 请教:jsp用unicode存放字符串到数据库(mysql),读出来是乱码,怎么办?
- 求大神帮我看看ftp不能启动的问题....
- jdk4.2+tomcat5.0 安装完后不好用?????
- 链接问题!!!急啊!!!
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*; public class onLineUser implements HttpSessionBindingListener {
public onLineUser(){
} private Vector users=new Vector();
public int getCount(){
users.trimToSize();
return users.capacity();
}
public boolean existUser(String userName){
users.trimToSize();
boolean existUser=false;
for (int i=0;i<users.capacity();i++ )
{
if (userName.equals((String)users.get(i)))
{
existUser=true;
break;
}
}
return existUser;
} public boolean deleteUser(String userName) {
users.trimToSize();
if(existUser(userName)){
int currUserIndex=-1;
for(int i=0;i<users.capacity();i++){
if(userName.equals((String)users.get(i))){
currUserIndex=i;
break;
}
}
if (currUserIndex!=-1){
users.remove(currUserIndex);
users.trimToSize();
return true;
}
}
return false;
} public Vector getOnLineUser()
{
return users;
}
public void valueBound(HttpSessionBindingEvent e) {
users.trimToSize();
if(!existUser(e.getName())){
users.add(e.getName());
System.out.print(e.getName()+"\t 登入到系统\t"+(new Date()));
System.out.println(" 在线用户数为:"+getCount());
}else
System.out.println(e.getName()+"已经存在");
} public void valueUnbound(HttpSessionBindingEvent e) {
users.trimToSize();
String userName=e.getName();
deleteUser(userName);
System.out.print(userName+"\t 退出系统\t"+(new Date()));
System.out.println(" 在线用户数为:"+getCount());
}
}