如何检查现有会话是否无效?在以下 loginBean 代码中,我检查了用户是否已登录的每次登录。如果其他系统已登录,请停用该会话并创建新会话。如果该会话因超时而失效,则下次 userSessionMap 包含 usedname 和错误以使其失效。那么如何检查它是否无效?
Map appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
Map<String, HttpSession> userSessionMap = (Map<String, HttpSession>) appMap.get("USERS");
if (userSessionMap.containsKey(getUsername())) {
log.info(getUsername() + " already loggedin. Closing existing sesssion");
HttpSession sess = userSessionMap.get(getUsername());
sess.invalidate();
}