我们如何在浏览器关闭事件上调用注销 servlet [英] How we call logout servlet on browser close event

查看:16
本文介绍了我们如何在浏览器关闭事件上调用注销 servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何处理浏览器的关闭事件以触发注销?

How can I handle the close event of a browser to trigger a logout?

推荐答案

前段时间我一直在寻找解决这个问题的一致解决方案,我的决定是在不相信浏览器或用户的情况下处理这种情况.

I've searched for a consistent solution to this problem some time ago, and my decision was to handle the situation without believing the browser or the user.

您无法确定用户是否以及何时离开您的页面,即使您使用onunload",您也可能无法在浏览器关闭或离开您的页面之前收到该事件.并且浏览器崩溃不会给您任何类型的信号,因此认为您知道用户仍在查看您的页面并可能采取任何进一步行动是有缺陷的.

You can't for sure know if a user is leaving your page and when, and even if you use 'onunload', you may not get the event before the browser closes or leaves your page. And browser crashes won't give you any kind of signal, so believing you know the user is still viewing you page and may take any further action is flawed.

关于注销用户的最佳做法是设置合适的会话超时,如果您需要进一步控制,您可以尝试在带有我还活着"信号的关键页面上添加 AJAX 调用,然后注销用户不再响应(这将需要启用 AJAX/JS 的浏览器并可能排除潜在用户).

The best you can do about logging out an user is put a fitting session timeout, and if you need further control, you may try adding AJAX calls on critical pages with 'I'm alive' signals, and then logging out users that are not responding anymore (that would require AJAX/JS enabled browser and may exclude potential users).

这篇关于我们如何在浏览器关闭事件上调用注销 servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆