不可能准确知道。
客户端进行了注销操作的话你就可以知道,并释放session。但如果客户端转到了其它网站或直接被关掉了,没有任何消息会发到server端,server就只好等超时了。
你就统计server端的session数就成了,一般都这么做。

解决方案 »

  1.   

    如何统计server端的session数呢?最好用代码说明,非常谢谢
      

  2.   

    哎,看看以前的帖子http://www.csdn.net/expert/topic/366/366150.xml?temp=.3149073使用Servlet 2.3新增web application listener可以搞定写一个Listener类对session的创建和消除进行侦听。import javax.servlet.*;
    import javax.servlet.http.*;public class CounterListener implements HttpSessionListener {
       private int count = 0;   public synchronized void sessionCreated(HttpSessionEvent se) {
           count++;
       }   public synchronized void sessionDestroyed(HttpSessionEvent se) {
           count--;
       }   public int getCount() {
           return count;
       }
    }
      

  3.   

    不过public synchronized void sessionDestroyed(HttpSessionEvent se) {
    这个是要等到这个session超时了才会触发,这个时间是服务器可定义的session超时时间。(即用户多久没动作后,这个session就没效超时)
      

  4.   

    有个错误static private int count