Come on,everybody,tell me how to do it!

解决方案 »

  1.   

    HttpSession.getAttributeNames()返回一个Enumeration对象,包含所有的属性名的集合,接下来的知道怎么做了吧。
      

  2.   

    javax.servlet.http 
    Interface HttpSessionContext--------------------------------------------------------------------------------
    Deprecated. As of Java(tm) Servlet API 2.1 for security reasons, with no replacement. This interface will be removed in a future version of this API. public abstract interface HttpSessionContextVersion: 
    $Version$ 
    Author: 
    Various 
    See Also: 
    HttpSession, HttpSessionBindingEvent, HttpSessionBindingListener--------------------------------------------------------------------------------Method Summary 
     java.util.Enumeration getIds() 
              Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return an empty enumeration and will be removed in a future version of this API. 
     HttpSession getSession(java.lang.String sessionId) 
              Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return null and will be removed in a future version of this API. 
      Method Detail 
    getSession
    public HttpSession getSession(java.lang.String sessionId)
    Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return null and will be removed in a future version of this API.--------------------------------------------------------------------------------getIds
    public java.util.Enumeration getIds()
    Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return an empty enumeration and will be removed in a future version of this API.
      

  3.   

    http://www.csdn.net/expert/Topic/138/138139.shtm回复人: xue_pear(王二) (2001-5-30 9:09:00)  得10分 
    登录加入:
    <jsp:useBean id="monitor" scope="application" class="java.util.HashMap" />monitor.put(session,user.getUserName());//user是个对象类
    UserMap map = new UserMap();
    map.setMap(monitor);
    session.setAttribute("Binder.object",map);UserMap是一个实现HttpSessionListener的类:
    import javax.servlet.http.HttpSessionBindingEvent;
    import javax.servlet.http.HttpSessionBindingListener;
    import java.util.*;public class UserMap implements HttpSessionBindingListener {
      private HashMap map;  public void valueBound(HttpSessionBindingEvent event) {
      }  public void valueUnbound(HttpSessionBindingEvent event) {
        map.remove(event.getSession());
      }  public void setMap(HashMap map){
        this.map = map;
      }
    }退出时jsp:
      ((HashMap)application.getAttribute("monitor")).remove(session);
      session.invalidate();查询在线用户jsp:
            HashMap monitor = ((HashMap)application.getAttribute("monitor"));
                              Iterator keyIter = monitor.keySet().iterator();                          while(keyIter.hasNext()){
                                HttpSession https = (HttpSession)keyIter.next();                            out.println("<tr>");                            out.println("<td bgcolor=\"EEEEEE\" width=\"5%\">");
                                out.println("<div align=\"center\">" + (String)monitor.get(https) + "</div>");
                                out.println("</td>");
    ....
    ....
    }
     
      

  4.   

    http://www.csdn.net/expert/Topic/156/156276.shtm
      

  5.   

    好像都是论坛里在线人数的统计。
    不是我想要的,我想要的是得到所有被建立的session对象。而且我也不想在客户端做个计时刷新。我要利用session会自动的由于浏览器的关闭而失效这个性质。
      

  6.   

    UserMap是一个实现HttpSessionListener的类:
    import javax.servlet.http.HttpSessionBindingEvent;
    import javax.servlet.http.HttpSessionBindingListener;
    import java.util.*;public class UserMap implements HttpSessionBindingListener {
      private HashMap map;  public void valueBound(HttpSessionBindingEvent event) {
      }  public void valueUnbound(HttpSessionBindingEvent event) {
        map.remove(event.getSession());
      }  public void setMap(HashMap map){
        this.map = map;
      }
    }
    上面的就达到你的目的(我要利用session会自动的由于浏览器的关闭而失效这个性质)
      

  7.   

    "我要利用session会自动的由于浏览器的关闭而失效这个性质."浏览器关闭时,session不会自动失效吧?我试过一个HttpSessionListener,当我关闭浏览器时,是不会有监听事件产生的。
      

  8.   

    补充:浏览器的关闭不能立刻体现session失效,要等time out session才能失效。
      

  9.   

    <jsp:useBean id="monitor" scope="application" class="java.util.HashMap" />
    monitor.put(session,new Date());//user是个对象类所有session 都放在 HashMap monitor 里,你可以把他们列出来,显示登陆时间,那不是完成你的目的吗。
      

  10.   

    要等到session time out,假如设的时间太长,那valueUnbound(HttpSessionBindingEvent event) 岂不是要很久才会执行?