2011-02-14 82 views
0

我是網頁設計新手。 那麼,有誰可以告訴我如何獲取有關所有打開的會話的信息? (我正在寫一款遊戲,我需要了解目前在線的所有客戶端) 我正在使用spring Mvc 3.0如何跟蹤Web應用程序中的會話?

感謝您的回答。

回答

1

對不起一次) 我處理我會是這樣的:

request.getSession(true).setAttribute("client",client); 
     request.getSession(true).setAttribute(Constants.SESS_AUTH, Boolean.TRUE); 

我的聽衆是

@Override 
public void sessionCreated(HttpSessionEvent arg0) { 
     totalActiveSessions++; 
     System.out.println("sessionCreated - add one client into list"); 
     setOnline(arg0); 
} 

@Override 
public void sessionDestroyed(HttpSessionEvent arg0) { 
     totalActiveSessions--; 
     System.out.println("sessionDestroyed - deduct one client from list"); 
     setOffline(arg0); 
} 

private void setOnline(HttpSessionEvent sessionEvent){ 

     HttpSession session = sessionEvent.getSession(); 

     ApplicationContext ctx = 
      WebApplicationContextUtils. 
        getWebApplicationContext(session.getServletContext()); 

     SessionService sessionService = (SessionService) ctx.getBean("sessionService"); 

     sessionService.setClientOnLine((Client)sessionEvent.getSession().getAttribute("client")); 
} 

private void setOffline(HttpSessionEvent sessionEvent){ 

     HttpSession session = sessionEvent.getSession(); 

     ApplicationContext ctx = 
      WebApplicationContextUtils. 
        getWebApplicationContext(session.getServletContext()); 

     SessionService sessionService = (SessionService) ctx.getBean("sessionService"); 

     sessionService.setClientOffLine((Client)sessionEvent.getSession().getAttribute("client")); 
} 

遺憾的是它不喜歡的工作,我想...... 你能推薦一下

+0

問題解決 只需要實現HttpSessionAttributeListener – Oleksii 2011-02-14 12:36:04