how to make session timeout with alert box

馋奶兔 提交于 2020-01-17 05:13:06

问题


I am using spring security, java in application. When the session gets expired, I need to show an alert that the session is over. The box should have an ok button which, when clicked, I want to redirect to login page.where should i put max time out and display alert message after time out.


回答1:


Assuming that the session timeout timer is reset once a new page is loaded, you can simply use a JavaScript timeout:

setTimeout(function() {
    if(confirm('session timeout'))
        location.href = 'login.html';
}, 15 * 60 * 1000); // 15 minutes, alter appropriately

As soon as you navigate to another page, all current JavaScript is discarded, so the timeout will be reset.




回答2:


if its an ajax-enabled website, check for auth/session on every ajax-request, return statuscode or similar on the request, and do a check for that on the client side. If statuscode 401, display alert.

I dont see the need to have a timer to trigger it after an idle period, to be honest.



来源:https://stackoverflow.com/questions/6759556/how-to-make-session-timeout-with-alert-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!