【问题标题】:Avoid session time out in Spring MVC避免 Spring MVC 中的会话超时
【发布时间】:2015-07-01 12:09:17
【问题描述】:

我使用会话变量传递所有必要的数据,当会话到期时,所有数据都将丢失。我希望它不会在特定的 jsp 上过期,但在其他 jsps 会话中它可以过期。

我建议根据计时器连续向服务器发送请求,以避免会话到期,特别是jsp。

我使用spring mvc。如何在特定的 jsp 上做到这一点?

我尝试了下面的代码,但我需要做的是不使用图像向服务器发送请求:

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

【问题讨论】:

    标签: java spring jsp spring-mvc session


    【解决方案1】:

    尝试使用 ajax 调用:

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

    【讨论】:

      【解决方案2】:
      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);
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-05-15
        • 2015-09-23
        • 2012-08-18
        • 2012-01-26
        • 2020-12-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多