我在论坛上搜过了,http://topic.csdn.net/t/20030109/15/1342697.html,这个里面的回答我试了试,但是我的服务器报错是,An error occurred at line: 185 in the jsp file: /jsp/blog.jsp
Generated servlet error:
D:\jakarta-tomcat-5.0.28\work\Catalina\localhost\tomcat\org\apache\jsp\jsp\blog_jsp.java:265: 找不到符号
符号: 类 Vector
位置: 类 org.apache.jsp.jsp.blog_jsp
          Vector  vt=onlineuser.getOnLineUser();   
          ^
An error occurred at line: 185 in the jsp file: /jsp/blog.jsp
Generated servlet error:
D:\jakarta-tomcat-5.0.28\work\Catalina\localhost\tomcat\org\apache\jsp\jsp\blog_jsp.java:266: 找不到符号
符号: 类 Enumeration
位置: 类 org.apache.jsp.jsp.blog_jsp
          Enumeration  e=vt.elements();   
          ^
有谁可以指教一下,谢谢了。

解决方案 »

  1.   

    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());
         }
    }