区分是否是ajax请求很简单只要判断rerquest的header里面x-requested-with是否为空;
常用在过滤器中用于标记请求属性以及是否拦截
public static void isAjaxRequest(HttpServletRequest request) { if (request.getHeader("x-requested-with") != null && request.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) { System.out.print("该请求是 AJAX 异步HTTP请求。"); }else{ System.out.print("该请求是传统的 同步HTTP请求。"); }