Java 在Spring MVC中避免会话超时
我使用session变量传递所有必要的数据,当session过期时,所有数据都将丢失。我不希望它在特定jsp上过期,但在其他jsp会话中它可能会过期 我建议根据计时器连续向服务器发送请求,以避免特定jsp中的会话过期 我使用SpringMVC。如何在特定jsp上执行此操作 我尝试了以下代码,但我需要做的是在不使用映像的情况下向服务器发送请求:Java 在Spring MVC中避免会话超时,java,spring,jsp,spring-mvc,session,Java,Spring,Jsp,Spring Mvc,Session,我使用session变量传递所有必要的数据,当session过期时,所有数据都将丢失。我不希望它在特定jsp上过期,但在其他jsp会话中它可能会过期 我建议根据计时器连续向服务器发送请求,以避免特定jsp中的会话过期 我使用SpringMVC。如何在特定jsp上执行此操作 我尝试了以下代码,但我需要做的是在不使用映像的情况下向服务器发送请求: function keepMeAlive(imgName) { myImg = document.getElementById(imgName);
function keepMeAlive(imgName) {
myImg = document.getElementById(imgName);
if (myImg) myImg.src = myImg.src.replace(/?.*$/, '?' + Math.random());
}
window.setInterval("keepMeAlive('keepAliveIMG')", 100000);
<img id="keepAliveIMG" width="1" height="1" src="http://www.some.url/someimg.gif?" />
函数keepMeAlive(imgName){
myImg=document.getElementById(imgName);
如果(myImg)myImg.src=myImg.src.replace(/?*$/,“?”+Math.random());
}
setInterval(“keepMeAlive('keepAliveIMG')”,100000);
尝试使用ajax调用:
函数keepAlive(){
$.get(window.location.pathname,函数(数据){console.log(数据)});
}
设置间隔(keepAlive,100000)代码>
function f(){
var oRequest = new XMLHttpRequest();
var sURL = "http://"
+ "localhost:8080/sessionAlivecheck/"
+ "/example/newjsp.jsp";
oRequest.open("GET",sURL,false);
oRequest.setRequestHeader("User-Agent",navigator.userAgent);
oRequest.send(null);
//alert("hhh");
}
$(document).ready(function () {
setInterval(f, 2000);
});