简体   繁体   English

避免在Spring MVC中会话超时

[英]Avoid session time out in Spring MVC

I pass all the necessary data using session variable and when session expires all the data will be lost. 我使用会话变量传递所有必需的数据,并且当会话到期时,所有数据都将丢失。 I want it not to expire on a particular jsp but when in other jsps session it can expire. 我希望它不会在特定的jsp上过期,但是在其他jsps会话中可以过期。

I propose sending a request to the server continuously according to the timer to avoid the session expiry in particular jsp. 我建议根据计时器连续向服务器发送请求,以避免会话过期,特别是在jsp中。

I use spring mvc. 我使用spring mvc。 How can I do this on particular jsp? 如何在特定的jsp上执行此操作?

I tried below code but I need to do is send a request to the server without using image: 我尝试了下面的代码,但我需要做的是不使用映像就将请求发送到服务器:

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?" />

Try using ajax calls: 尝试使用ajax调用:

 function keepAlive(){ $.get( window.location.pathname, function( data ) {console.log(data)} ); } window.setInterval(keepAlive, 100000); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM