session过期情况下ajax请求不会触发重新登录的问题

  • 在拦截器中添加以下逻辑
String requestType = request.getHeader("X-Requested-With");
            if (!StringUtils.isEmpty(requestType) && requestType.equalsIgnoreCase("XMLHttpRequest")) {
                response.setHeader("sessionStatus", "timeout");
                response.sendError(518, "session timeout.");
            }

 

  • 页面ajax配置全局函数:
//定义ajax全局事件
$(document).ajaxError(function(jqxhr, error) {
    var sessionStatus = error.getResponseHeader("sessionStatus");
    if (sessionStatus == "timeout") {
        $.MsgBox.Alert("系统提示", "您的登录信息已过期,请重新登录!", function(){
            top.location.href = "${pageContext.request.contextPath}";
        })
    }
    var operationStatus = error.getResponseHeader("operationStatus");
    if (operationStatus == "refused") {
        $.MsgBox.Alert("系统提示", "您没有权限执行该操作!", function(){
            top.location.href = contextPath;
        })
    }
});

 

posted @ 2019-02-28 17:40  聪明的娃  阅读(82)  评论(0编辑  收藏  举报