ajax请求被拦截器拦截,解决拦截器对ajax请求的拦截实例详解

解决拦截器对ajax请求的的拦截

拦截器配置:public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object obj) throws Exception { //获取判定登陆的session是否存在 String token = (String) request.getSession().getAttribute("token"); String postId = (String) request.getSession().getAttribute("postId"); if(token == null || token == ""){ String XRequested =request.getHeader("X-Requested-With"); if("XMLHttpRequest".equals(XRequested)){ response.getWriter().write("IsAjax"); }else{ response.sendRedirect("/m-web/user/toLogin"); } return false; } if(postId == null || postId == ""){ String XRequested =request.getHeader("X-Requested-With"); if("XMLHttpRequest".equals(XRequested)){ response.getWriter().write("IsAjax"); }else{ response.sendRedirect("/m-web/user/toLogin"); } return false; } return true; }

你可能感兴趣的:(ajax请求被拦截器拦截)