经常会遇到一种场景,直接访问某些权限被拒绝后跳转登陆页面,然而ajax不会跳转
这个时候使用全局的:
1 2 3 4 5 6 7 8 9 10 11 12
| $(function(){
$.ajaxSetup({ complete:function(XMLHttpRequest,textStatus){ var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); if(sessionstatus=="timeout"){ window.location.replace(urlconfig.url.ctx+"/login.jsp"); } } }) })
|
在拦截器里面:
1 2 3 4 5 6 7 8 9
| if (httpRequest.getHeader("x-requested-with") != null && httpRequest.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) { httpResponse.setHeader("sessionstatus", "timeout"); httpResponse.setStatus(403); return false; } else { httpResponse.sendRedirect(httpResponse.encodeRedirectURL("/login.jsp")); }
|