如何在Web应用程序中跟踪会话?

时间:2011-02-14 11:04:34

标签: session spring-mvc

我是网页设计的新手。 那么,任何人都可以告诉我如何获取有关所有已打开会话的信息吗? (我正在写一个游戏,我需要了解所有在线的客户) 我正在使用spring Mvc 3.0

感谢您的回答。

1 个答案:

答案 0 :(得分: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"));
}

不幸的是它并不像我想要的那样...... 你能推荐什么吗

相关问题