if (isLogin) { //Forbid Multiple Login //User login success, refresh session map, if multiple login, make the exists session invalid String sessionIdFromMap = SessionListener.userMap.get(portalLoginName); String sessionIdFromReq = request.getSession().getId(); logger.debug("-------Session ID from user map: {}---------", sessionIdFromMap); logger.debug("-------Session ID from request: {}---------", sessionIdFromReq); if(sessionIdFromMap != null&&!sessionIdFromMap.equals("")){ if(sessionIdFromMap.equals(sessionIdFromReq)){ logger.debug("======session map equals request session id====="); SessionListener.sessionMap.get(sessionIdFromMap).invalidate(); SessionListener.userMap.put(portalLoginName, sessionIdFromReq); SessionListener.sessionMap.put(sessionIdFromReq, request.getSession()); }else{ if (SessionListener.userMap.containsKey(portalLoginName)) { logger.debug("=========the same user multiple login========="); SessionListener.sessionMap.get(sessionIdFromMap).invalidate(); SessionListener.userMap.put(portalLoginName, sessionIdFromReq); SessionListener.sessionMap.put(sessionIdFromReq, request.getSession()); } } logger.debug("=====new session to put into map===="); SessionListener.userMap.put(portalLoginName,request.getSession().getId()); SessionListener.sessionMap.put(request.getSession().getId(),request.getSession()); .... }
listener:
public class SessionListener implements HttpSessionListener { private static final Logger logger = LoggerFactory.getLogger(SessionListener.class); public static Map<String, String> userMap = new HashMap<>(); public static Map<String, HttpSession> sessionMap = new HashMap<>(); @Override public void sessionCreated(HttpSessionEvent se) { // TODO Auto-generated method stub } @Override public void sessionDestroyed(HttpSessionEvent se) { HttpSession session = se.getSession(); String sessionId = session.getId(); logger.debug("-------------session[{}] destroy---------", sessionId); sessionMap.remove(sessionId); for (String key : userMap.keySet()) { if (userMap.get(key).equals(sessionId)) { userMap.remove(key); } } } }
web.xml:
<listener> <listener-class>com.hkt.umg.unified.portal.web.SessionListener</listener-class> </listener>
思路:
1.如果第一次登陆,记录登陆的session id
2.如果第二次登陆的session id和第一次相同,而且登录名也一样,则清除掉第一次的session;若session id不同则记录第二次的session id
参考:
https://blog.csdn.net/football98/article/details/52777575
相关推荐
多文档文本编辑器--Multiple Documents Text Editor 使用java语言按照java Bean 规范进行开发,基于MVC模型, 编码规范简洁,结构紧凑,且有详细注释,很适用于java初学者 作为进阶的参考! 该软件实现了多文档编辑...
multiple-shiro-login multiple shiro login shiro配置文件 portal: SecurityConfig.java 过滤/请求,不包含/admin/ admin: AdminSecurityConfig.java 过滤/admin/**请求 因为/**包含/admin/**,所以需要优先过滤/...
SSD3所有Multiple-Choice 的整合带答案 对Java部分的学习有帮助
Java Platform Standard Edition 7 Documentation What's New Documentation Release Notes Tutorials and Training The Java Tutorials Java Training More Information Java SE 7 Names and ...
Multiple Terrain Brush is an editor tool with brushes for heightmaps and textures that work on multiple terrains. You can easily paint heightmap and textures, without switching from terrain to terrain...
pyimagesearch 的Keras Multiple outputs and multiple losses 代码复现。包含数据集。
多选框要用到的js multiple-Select.js 用的时候引用到文件中
“Spatial channel model for multiple input multiple output (MIMO) simulations (Release 13),” 3GPP , Tech. Rep. 25.996, Dec. 2015. 2015年版的3GPP TR-25996的标准
2.2.5No More Multiple Inheritance 2.2.6No More Goto Statements 2.2.7No More Operator Overloading 2.2.8No More Automatic Coercions 2.2.9No More Pointers 2.3Summary 3. Java is Object ...
Separate the wiring of multiple modules from application logic Use Java annotations for configuration Master the scripting API built into the Java language Understand static versus dynamic ...
Multiple Resource Representations Binding a Request to a Resource Entity Providers Client API Mapping Exceptions Filters and Entity Interceptors Validation of Resources Chapter 5 : SOAP...
Volume I quickly brings you up-to-speed on Java SE 7 core language enhancements, including the diamond operator, improved resource handling, and catching of multiple exceptions. All of the code ...
Multiple_Graph_And_Chart_UI_Pack_v1.2
1. The name of a Java source file (a) has no restrictions (b) must be the same as the class it defines, ignoring case (c) must use the extension .class (d) must be the same as the class it defines, ...
We've found that books that deal with these other APIs tend to give short shrift to how multiple threads can fully utilize these features of Java (though doubtless the reverse is true; we make no ...
switching between multiple views of an object, integration of pen input with interpreters, libraries for manipulating ink strokes, widgets optimized for pens, and compatibility with Java’s Swing ...
Multiple_choice.java多选题类 Right_or_wrong_question.java判断题类 UserRecord.java为用户记录类 User.tet为用户文件 UserRecord.txt为用户做题记录文件 TestExam.java为做题主程序 最后在命令行下运行 用javac ...
Tracking radar targets with multiple reflection points
Windows 10 Education / Enterprise / Multiple Editions Full 带 N 的版本,英文合集 2015.7.29 Windows 10 Education / Enterprise / Multiple Editions Full [32-64 bit] (Size: 24.31 GB) en_windows_10_n...