如何使带有警报框的会话超时

问题描述:

我在应用程序中使用Spring Security,java.当会话过期时,我需要显示会话已结束的警报.框上应该有一个确定按钮,单击该按钮后,我想重定向到登录页面.我应该在其中放置最大超时时间,并在超时后显示警报消息.

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.

假设加载新页面后会话超时计时器已重置,则只需使用JavaScript超时即可:

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

导航到另一个页面后,所有当前的JavaScript都会被丢弃,因此超时将被重置.

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