diff --git a/src/main/resources/modules/SpringBoot/java/action/GlobalController.java b/src/main/resources/modules/SpringBoot/java/action/GlobalController.java index e3fe49b7..ae9beafa 100644 --- a/src/main/resources/modules/SpringBoot/java/action/GlobalController.java +++ b/src/main/resources/modules/SpringBoot/java/action/GlobalController.java @@ -33,6 +33,7 @@ import ${basePackage}.frame.utils.AESUtil; import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.MD5Util; import ${basePackage}.frame.utils.MapperUtil; +import ${basePackage}.frame.utils.RequestUtil; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -113,7 +114,8 @@ public class GlobalController implements ErrorController { case 404: return "404"; case 403: - if ((request.getServletPath().equals(homePage) || request.getServletPath().equals("/")) && LocalData.getToken() == null) { + String errorUrl = RequestUtil.getErrorUrl(request); + if ((errorUrl.equals(homePage) || errorUrl.equals("/")) && LocalData.getToken() == null) { try { response.sendRedirect("/login.htm"); } catch (IOException e) { diff --git a/src/main/resources/modules/SpringBoot/java/frame/utils/RequestUtil.java b/src/main/resources/modules/SpringBoot/java/frame/utils/RequestUtil.java index eb45c6ac..d332bf8c 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/utils/RequestUtil.java +++ b/src/main/resources/modules/SpringBoot/java/frame/utils/RequestUtil.java @@ -56,11 +56,24 @@ public class RequestUtil { /** * 获取情况方客户端信息 * - * @param request - * @return + * @param request 请求 + * @return 客户端信息 */ public static String getUserAgent(HttpServletRequest request) { return request.getHeader("User-Agent"); } + /** + * 获取转发至错误页之前的请求URL + * + * @param request 请求 + * @return 请求URL + */ + public static String getErrorUrl(HttpServletRequest request) { + if (request.getAttribute("javax.servlet.error.request_uri") != null) { + return (String) request.getAttribute("javax.servlet.error.request_uri"); + } else { + return ""; + } + } }