怎么能够知道当前有多少用户连接到了TOMCAT呢? 怎么能够知道当前有多少用户连接到了TOMCAT呢?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用HttpSessionListener监听session的创建,数量保存在application中 package li;/** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2006</p> * * <p>Company: </p> * * @author not attributable * @version 1.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()); }} 既然基于数据库,最简单的方式就是在数据库中作一个标记。实际上,随着功能的铺开,可能会产生很多个类似统计,比如在线访客数量、在线VIP数量、在线网管数量、历史最高在线访客数量、历史最高在线VIP数量……用数据库无疑更容易扩展。 用数据库中用户状态比读取session更容易控制最好是方法是,在读取数据库中用户状态时,加上读取session,这样可以排除非法关机(或退出系统)数据库不能及时更新 Js相关问题 请教一个插入语句的错误 希望得到各位的帮助,js问题~~ 做网页游戏有发展吗? Java的小问题SmartUpload 怎么样取得Session的值(在监听session实现一个接口中)? 我用以下java写了一个发邮件的程序,运行时得如下错误,why?????? 问个关于RESIN1.1问题 jbuilder 看过来,看过来 一个小问题,关于<select> 谁有去页眉页脚的打印哦? 100分求sqlserver200中text类型,用hibernate解决
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.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());
}
}
最好是方法是,在读取数据库中用户状态时,加上读取session,这样可以排除非法关机(或退出系统)数据库不能及时更新