From 587e98cfa8357ba2a49f7cd825a40a5e73284b00 Mon Sep 17 00:00:00 2001 From: sh Date: Wed, 20 May 2026 12:47:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9401=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/ServletUtils.java | 21 +++++++++++++++++++ .../handle/AuthenticationEntryPointImpl.java | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java index 10a670a..666dc2d 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java @@ -152,6 +152,27 @@ public class ServletUtils } } + /** + * 将字符串渲染到客户端——不转移 + * + * @param response 渲染对象 + * @param string 待渲染的字符串 + */ + public static void renderStringRaw(HttpServletResponse response, String string) + { + try + { + response.setStatus(200); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + response.getWriter().print(string); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + /** * HTML转义(修复XSS漏洞) * @param content diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java index bd20aa3..296fe22 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java @@ -29,7 +29,7 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S { int code = HttpStatus.UNAUTHORIZED; String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI()); - ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.unAuth(code, msg))); + ServletUtils.renderStringRaw(response, JSON.toJSONString(AjaxResult.unAuth(code, msg))); // response.setStatus(HttpStatus.UNAUTHORIZED); } }