// 实现roomkey userList vChat 的初始化 public String execute() throws Exception { user = (User) session.get(AuthenticationInterceptor.USER_SESSION_KEY); // 将房间的roomid设到application中 Hashtable roomKey = (Hashtable) application.get("roomKey"); if (roomKey == null) { roomKey = new Hashtable(); } if (chatcounts != null) { roomKey.put(user.getUsername(), chatcounts); application.put("roomKey", roomKey); } // 使用roomKey对应的用户所对应的roomid作为用户list的键 String userKey = (String) roomKey.get(user.getUsername()); // 构建一个Hashtable对象,以存储在线用户信息 Hashtable userList = (Hashtable) application.get(userKey); if (userList == null) { userList = new Hashtable(); } // 将当前登录用户信息添加到在线用户列表中 userList.put(user.getUsername(), user.getUsername() + "**" + user.getSex() + "***"); application.put(userKey, userList); // 使用roomKey对应的用户所对应的roomid+"chatKey"字符创作为聊天内容list的键 String chatKey = (String) roomKey.get(user.getUsername()) + "chatKey"; Vector vChat = (Vector) application.get(chatKey); if (vChat == null) { vChat = new Vector(); } // 将用户进入聊天室的消息加入聊天信息中 String sWel = "<font color=red>" + user.getUsername() + "</font> 进入了聊天室!<br>"; vChat.add(sWel); application.put(chatKey, vChat); return "success"; }
// 刷新用户信息 public String userinfo() { user = (User) session.get(AuthenticationInterceptor.USER_SESSION_KEY); Hashtable roomKey = (Hashtable) application.get("roomKey"); // 使用roomKey对应的用户所对应的roomid作为用户list的键 String userKey = (String) roomKey.get(user.getUsername()); // 构建一个Hashtable对象,以存储在线用户信息 Hashtable userList = (Hashtable) application.get(userKey); // 将当前登录用户信息添加到在线用户列表中 userList.put(user.getUsername(), user.getUsername() + "**" + user.getSex() + "***"); application.put(userKey, userList); return "userinfo"; }