- 在拦截器中添加以下逻辑
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; }) } });
原文地址:https://www.cnblogs.com/zhoujl-5071/p/10451903.html
时间: 2024-10-11 03:29:34