简体   繁体   English

当用户将页面留在jsf中时,如何使会话无效?

[英]How to invalidate a session when the user leaves the page in jsf?

People, how i can know when a user changed the address and leave the page? 人,我怎么知道用户何时更改地址并离开页面? I'm using JSF 1.2 and my boss want this little feature, like, he is on the page and then he put other address ctrl+L then www.foo.com and when he comes back to the page the session still valid so he don't need to pass by the login screen, how to invalidate when this event happens? 我正在使用JSF 1.2,而我的老板想要这个小功能,例如,他在页面上,然后他输入其他地址ctrl + L,然后输入www.foo.com,当他返回页面时,该会话仍然有效,因此他不需要经过登录屏幕,该事件发生时如何无效?

The only way is to bind a JavaScript function to <body onunload='...'> ( http://www.w3schools.com/jsref/event_onunload.asp ). 唯一的方法是将JavaScript函数绑定到<body onunload='...'>http://www.w3schools.com/jsref/event_onunload.asp )。

Here's a example: 这是一个例子:

<script type="application/javascript">
function logout() {
   var xhr = XMLHttpRequest();
   xhr.open('get', '/logout', false);
   xhr.send(null);
}
</script>
....
<body onunload="logout()"> ...

This way, when the user leaved the page, the browser will issue a request to /logout URL. 这样,当用户离开页面时,浏览器将向/logout URL发出请求。 On the server side, invalidate any user session that requests /logout . 在服务器端,使所有请求/logout用户会话无效。

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

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