From 7cc4372da71ea427939137929345a2113feb7665 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Thu, 21 May 2020 12:16:05 +0800 Subject: [PATCH] =?UTF-8?q?=5F=5Fajax=3Djson=20=E6=94=AF=E6=8C=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=88=B0=20header=20=E9=87=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeesite/common/web/http/ServletUtils.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java b/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java index ee8ace8c..9ada8e4f 100644 --- a/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java +++ b/common/src/main/java/com/jeesite/common/web/http/ServletUtils.java @@ -103,12 +103,22 @@ public class ServletUtils { public static boolean isAjaxRequest(HttpServletRequest request){ String accept = request.getHeader("accept"); - if (accept != null && accept.indexOf(MediaType.APPLICATION_JSON_VALUE) != -1){ + if (StringUtils.contains(accept, MediaType.APPLICATION_JSON_VALUE)){ return true; } - + String xRequestedWith = request.getHeader("X-Requested-With"); - if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1){ + if (StringUtils.contains(xRequestedWith, "XMLHttpRequest")){ + return true; + } + + String ajaxHeader = request.getHeader("__ajax"); + if (StringUtils.inStringIgnoreCase(ajaxHeader, "json", "xml")){ + return true; + } + + String ajaxParameter = request.getParameter("__ajax"); + if (StringUtils.inStringIgnoreCase(ajaxParameter, "json", "xml")){ return true; } @@ -118,11 +128,6 @@ public class ServletUtils { return true; } - String ajax = request.getParameter("__ajax"); - if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")){ - return true; - } - return false; }