如果用户在java中关闭浏览器,如何清除httpsession [英] How to clear the httpsession, if the user close the browser in java

查看:737
本文介绍了如果用户在java中关闭浏览器,如何清除httpsession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果消费者关闭浏览器窗口,我试图清除HttpSession。我不知道该怎么做,请帮助我的人



谢谢,问候
Chakri

解决方案

如果您可以让浏览器(可靠地)通知服务器,窗口,那么服务器可以根据ejay_francisco提供的原始答案调用 session.invalidate()



难以让通知可靠地发生。有很多方法可以检测窗户关闭;例如(以及类似的):



然后,您可以编写(javascript)关闭事件处理程序向服务器发送特定请求。



但是,不要以为任何方案都能够处理用户浏览器死亡,用户机器关闭以及类似情况的情况。所以,如果你需要在100%的时间内清除会话,那么你可能不是很幸运。我认为不能这样做。


I am trying to clear the HttpSession if the consumer close the browser window. I dont know how to do it, Please help me anyone

Thanks & Regards Chakri

解决方案

If you could get the browser to (reliably) notify the server that the user had closed the window, then the server could call session.invalidate() as per the original Answer provided by ejay_francisco.

The difficulty is getting the notification to happen reliably. There are various ways to detect the window close; e.g. as covered by these Questions (and similar):

You could then write the (javascript) close event handler to send a specific request to the server.

However, I don't think any scheme is going to be able to deal with cases where the user's browser dies, the user's machine is shut down, and similar scenarios. So if you need the session to be cleared 100% of the time, then you are probably out of luck. I don't think it can be done.

这篇关于如果用户在java中关闭浏览器,如何清除httpsession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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