【问题标题】:session timeout issue using ajax使用ajax的会话超时问题
【发布时间】:2016-04-03 20:04:58
【问题描述】:

我有 2 个应用程序,一个在 struts 中,另一个在 spring 中。从 struts 应用程序我有一个链接,它将通过返回 model 的 ajax 调用调用 spring 应用程序控制器。

在 struts 应用程序中,我有 20 分钟的会话超时,并且在为在 struts 应用程序中呈现的 spring 应用程序执行任何事务时,struts 应用程序中的会话超时保持不变,并且在 20 分钟后它会注销。

struts 应用 jsp 页面。

    <body>
<div id="content"></div>
</body>
<script type="text/javascript">

     $(document).ready(function() {
         var sessionId = '<%= sessionId %>'

         $.ajax({
         type: "GET",
         url: '/springapp/index.app?id='+sessionId,
         data: "" ,
        success: function(response){
            $('#content').html(response);
        },
        error: function(e){
        alert('Error: ' + e);
        console.log(e)
        }
    });


    });
</script>

Spring 应用程序控制器。

@RequestMapping(value = "/*.app", method = {RequestMethod.GET, RequestMethod.POST})
    public String jspController(ServletRequest req, ServletResponse res) throws exception {
        LOGGER.debug("inside jspController() start");
        HttpServletRequest request = (HttpServletRequest) req;
        String model = request.getRequestURI();
        if (model.endsWith("index.app")) {
            String sessionKey = request.getParameter("employeeId");
            SpringStrutsHandshake springStrutsHandshake = securityDelegate.getUserId(sessionKey);
            User user = userDelegate.getUserByEmployeeId(springStrutsHandshake.getUserId());
            user.setSessionKey(sessionKey);
            request.setAttribute("USER", user);
            model = "candidateList";
        } else {
            model = model.substring(model.lastIndexOf("/") + 1, model.lastIndexOf("."));
        }
        return model;
    }

当呈现的 spring 应用程序页面中有任何事务时,您能帮我解决超时问题吗?

【问题讨论】:

    标签: javascript spring session timeout


    【解决方案1】:

    如果您不希望 struts 应用程序中的会话超时,您为什么不定期(可能每 15 分钟)向 struts 应用程序发送请求,它什么都不做,只是为了防止会话空闲,直到春天应用回调。

    或者你可以像这样添加一个动态设置会话超时时间的方法

    request.getSession.setMaxInactiveInterval(60*60); //in seconds
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-17
      • 2012-01-12
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      相关资源
      最近更新 更多