简体   繁体   English

避免在Web应用程序中进行多次登录

[英]Avoid Multiple logins in a web-application

The website is having auto-refresh.When an user login with the same username that is logged in already somewhere,how to logout the previous login?How to give a relogin page in the first browser window? 网站正在自动刷新。当用户使用已经在某个地方登录的相同用户名登录时,如何注销以前的登录名?如何在第一个浏览器窗口中提供重新登录页面?

  Please provide some code snippets....


   Thanks in advance....

This post is dealing with a similar problem. 这篇文章正在处理类似的问题。

Without you specifying more details, it's difficult to answer your question properly. 如果没有指定更多细节,很难正确回答您的问题。 First of all, if a user opens another tab or window within the same browser, they will be still logged in using the previous login. 首先,如果用户在同一浏览器中打开另一个选项卡或窗口,则他们仍将使用以前的登录名登录。 This is normal behaviour. 这是正常行为。

If a user logs in using a different browser, then one thing you can do: 如果用户使用其他浏览器登录,则可以执行以下操作:

  1. register a HttpSessionListener 注册一个HttpSessionListener
  2. when a session is created, using void sessionCreated(HttpSessionEvent se) , check if user's credentials and session id are in your database 创建会话时,使用void sessionCreated(HttpSessionEvent se) ,检查用户的凭据和会话ID是否在您的数据库中
  3. if not, put them in a database table 如果没有,请将它们放在数据库表中
  4. if yes, then invalidate their previous session by deleting previous credentials in database 如果是,则通过删除数据库中的先前凭证使其先前的会话无效
  5. when a session is destroyed, using void sessionDestroyed(HttpSessionEvent se) delete user's credentials in database 当会话被销毁时,使用void sessionDestroyed(HttpSessionEvent se)删除数据库中的用户凭据

One other thing. 另一件事。 If you're going to use this approach, then you'll have to check with every browser request if your user's credentials are stored in a database. 如果要使用此方法,则必须检查每个浏览器请求,如果您的用户凭据存储在数据库中。 You can use a Servlet filter for this. 您可以使用Servlet 过滤器 This will, of course, be an overhead. 当然,这将是一个开销。

One more thing. 还有一件事。 If there's an exception in your session creation/destruction code, there's a danger of user's credentials aren't properly disposed of in database. 如果会话创建/销毁代码中存在异常,则存在用户凭据未正确处理在数据库中的危险。 You can handle this using database triggers to delete rows that are as old as your session timeout is. 您可以使用数据库触发器来处理此操作,以删除与会话超时一样长的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM