所有的session信息可以保存在内存中,提供系统处理(添加/删除/修改)。
不知道楼主想怎么实现!如果系统允许同名用户同时从n台客户端来访问,只能象classjava(原始野人) 所说的通过sessionID来识别;反之,可以通过系统用户ID来识别。

解决方案 »

  1.   

    public class Listener extends HttpServlet implements  HttpSessionListener
      

  2.   

    //Notification that a session was created
        public void sessionCreated(HttpSessionEvent se) {
            throw new java.lang.UnsupportedOperationException("Method sessionCreated() not yet implemented.");
        }    //Notification that a session was invalidated
        public void sessionDestroyed(HttpSessionEvent se) {
            throw new java.lang.UnsupportedOperationException("Method sessionDestroyed() not yet implemented.");
        }
      

  3.   

    不知道你懂了没有?重点研究一下HttpSessionListener接口就知道了
      

  4.   

    可以通过URL传输SESSIONID的方法
      

  5.   

    mport javax.servlet.http.*;
    import javax.servlet.*;
    import java.util.*;
    import org.apache.log4j.Logger;public class OnLineUser implements HttpSessionBindingListener {
      public  static Logger log = Logger.getLogger(OnLineUser.class.getName());
         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());
               log.info(e.getName()+"\t   登入到系统\t"+(new Date())+"      在线用户数为:"+getCount());
           }else
               //System.out.println(e.getName()+"已经存在");
               log.info(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());
           log.info(userName+"\t   退出系统\t"+(new Date()) + "      在线用户数为:"+getCount());
         }
    }