From 8d6a2305324438726e7c009c6249aa7aa1319e5f Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期一, 22 八月 2022 10:24:30 +0800 Subject: [PATCH] 优化Context信息,防止泄漏问题 --- src/main/java/com/ruoyi/common/utils/ServletUtils.java | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ruoyi/common/utils/ServletUtils.java b/src/main/java/com/ruoyi/common/utils/ServletUtils.java index a10c8ed..1cbf72f 100644 --- a/src/main/java/com/ruoyi/common/utils/ServletUtils.java +++ b/src/main/java/com/ruoyi/common/utils/ServletUtils.java @@ -1,12 +1,16 @@ package com.ruoyi.common.utils; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.text.Convert; /** @@ -99,9 +103,8 @@ * * @param response 娓叉煋瀵硅薄 * @param string 寰呮覆鏌撶殑瀛楃涓� - * @return null */ - public static String renderString(HttpServletResponse response, String string) + public static void renderString(HttpServletResponse response, String string) { try { @@ -114,7 +117,6 @@ { e.printStackTrace(); } - return null; } /** @@ -125,13 +127,13 @@ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); - if (accept != null && accept.indexOf("application/json") != -1) + if (accept != null && accept.contains("application/json")) { return true; } String xRequestedWith = request.getHeader("X-Requested-With"); - if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) + if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) { return true; } @@ -143,10 +145,42 @@ } String ajax = request.getParameter("__ajax"); - if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")) + return StringUtils.inStringIgnoreCase(ajax, "json", "xml"); + } + + /** + * 鍐呭缂栫爜 + * + * @param str 鍐呭 + * @return 缂栫爜鍚庣殑鍐呭 + */ + public static String urlEncode(String str) + { + try { - return true; + return URLEncoder.encode(str, Constants.UTF8); } - return false; + catch (UnsupportedEncodingException e) + { + return StringUtils.EMPTY; + } + } + + /** + * 鍐呭瑙g爜 + * + * @param str 鍐呭 + * @return 瑙g爜鍚庣殑鍐呭 + */ + public static String urlDecode(String str) + { + try + { + return URLDecoder.decode(str, Constants.UTF8); + } + catch (UnsupportedEncodingException e) + { + return StringUtils.EMPTY; + } } } -- Gitblit v1.9.3