String requestType = request.getHeader("X-Requested-With"); if (!StringUtils.isEmpty(requestType) && requestType.equalsIgnoreCase("XMLHttpRequest")) { response.setHeader("sessionStatus", "timeout"); response.sendError(518, "session timeout."); }
//定義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; }) } });