当用户确认保持联机时刷新会话时间



我正在研究JSF框架。在 Web 中.xml会话超时时间为 5 分钟。4 分钟后,我向用户显示确认对话框是否保持活动状态。单击"是"后,我尝试了sessionObject.setMaxInactiveInterval(5(。但是会话在第 5 分钟后失效。有没有办法在不更改 web.xml 中的时间的情况下动态延长用户会话时间。

public void refreshSession(){
//code to refresh the session
System.out.println("want to stay alive");
HttpSession currentSession = ServerUtility.getSession();
currentSession.setMaxInactiveInterval(2*60);
}

> Web.xml设置超时设置为全局,适用于整个应用程序。
但是,如果要延长会话时间,则需要创建包含以下代码的方法:

HttpSession session = request.getSession();
session.setMaxInactiveInterval(5*60);


您可以做的是创建一个执行上述代码
的端点

public void extendSession(){
HttpSession session = request.getSession();
session.setMaxInactiveInterval(5*60);
}

如果用户不想继续,则以下代码将立即结束会话:

session.setMaxInactiveInterval(0); // inactive immediately

最新更新