首页 > 解决方案 > 会话已过期

问题描述

在我的 Web 应用程序中,当会话过期时,我必须再次刷新 (F5) 网页才能继续使用该应用程序,否则,它将返回错误“OOps 出现问题,会话已过期”

我做了这样的事情:

http.sessionManagement()
.maximumSessions(1)
.expiredUrl("/start")
.and().invalidSessionUrl("/start");

应用:

server.port: 8080

但这只有在我刷新网站时才有效,否则它将不起作用有什么建议吗?

标签: javaspringspring-bootspring-security

解决方案


放置一个 keepalive 脚本,用于重置会话超时,或检查会话是否已过期并自动重定向用户。

var pingFrequency = 30;

// initializes the keep-alive settings
$(function() {
    setKeepAliveTimeout();
});

// executes a ping after pingFrequency
function setKeepAliveTimeout() {
    setTimeout(keepAlivePing, pingFrequency * 1000);
}

// executes the keepAlivePing, schedules a new ping if required
function keepAlivePing() {
    $.get("/keep-alive/ping", function (response) {
        if (/* check the response conditions */) {
            setKeepAliveTimeout();
        }
    });
}

推荐阅读