1、判断普通请求还是ajax请求分别跳转
if(isAjaxRequest){//是ajax请求 PrintWriter wirter = response.getWriter(); wirter.write("timeout"); wirter.flush(); } else {//非ajax请求直接跳转 response.sendRedirect(loginUrl + "?service=" + service); }
2、ajax请求超时处理
$.ajaxSetup({ global: false,type: "POST",complete: function (XMLHttpRequest,textStatus) { var data = XMLHttpRequest.responseText; if (data == "timeout") { //if( window.top != window.self ){ // window.top.location = "${pageContext.request.contextPath}"; alert('请重新登录!'); //} } } });原文链接:https://www.f2er.com/ajax/161857.html