我现在在做一个项目,项目是一个公司的办公自动化系统(oa)
遇到了一个问题,就是不能实现了那个在线人数的问题,怎么说呢?
用了很多方法,都是不行,做的都可以记录每一个人上线了,但是在先上线的不能得到最新的再线人数?
都用了很多种方式,就是不行(session,cookie,contextpage,==)
代码忘带了.
这个项目是自己练习用的,不是很难的.
Tanks my friends?

解决方案 »

  1.   

    public void doGet(HttpServletRequest request, HttpServletResponse  
                                 response)  throws ServletException, IOException { HttpSession session = request.getSession(true); 
    Object count = session.getAttribute("COUNTER");
    int counter = 0;
    if (count == null) {
           counter = 1;
           //将第一次计数存入session
           session.setAttribute("COUNTER", new Integer(1));
                   } else {
                         counter = ((Integer) count).intValue();
                         counter++;//计数加一
    //将计数存入session
    session.setAttribute("COUNTER", new Integer(counter));
                   }
    }
      

  2.   

    用ajax配合js中的计时器,刷新下页面。
      

  3.   


    Integer counter = (Integer)application.getAttribute("counter");if(counter == null) {
      application.setAttribute("counter", new Integer(1));
      out.println("共被点击 1 次");}else{
      counter = new Integer(counter.intValue() + 1);
      application.setAttribute("counter", counter);
      out.println("共被点击 " + counter + " 次");}
      

  4.   

             因为第一次上线时,计数器读出的是null,判断下应该就可以了
      

  5.   

    这个应该还是刷新的问题,先登录的没有及时刷新,所以看不到最新上线人数,
    用ajax做刷新就可以,可以每隔几秒就调用一个JS计时器,得到session中保存的最新上线人数