From f2ec819315330ed226ae7925e7cfc8993af6e5de Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Mon, 4 Nov 2024 18:37:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/smartboot/servlet/Container.java | 7 +++++++ .../smartboot/servlet/WebXmlParseEngine.java | 1 + .../servlet/conf/DeploymentInfo.java | 19 ++++++++++++++++++- .../smartboot/servlet/conf/WebAppInfo.java | 9 +++++++++ .../servlet/impl/ServletContextImpl.java | 5 +++-- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/servlet-core/src/main/java/tech/smartboot/servlet/Container.java b/servlet-core/src/main/java/tech/smartboot/servlet/Container.java index fb3aab0..1a124a0 100644 --- a/servlet-core/src/main/java/tech/smartboot/servlet/Container.java +++ b/servlet-core/src/main/java/tech/smartboot/servlet/Container.java @@ -401,6 +401,13 @@ private ServletContextRuntime getServletRuntime(String localPath, String context //set session timeout deploymentInfo.setSessionTimeout(webAppInfo.getSessionTimeout()); deploymentInfo.setLoginConfig(webAppInfo.getLoginConfig()); + if (StringUtils.isNotBlank(webAppInfo.getVersion())) { + String[] array = webAppInfo.getVersion().split("\\."); + if (array.length == 2) { + deploymentInfo.setEffectiveMajorVersion(Integer.parseInt(array[0])); + deploymentInfo.setEffectiveMinorVersion(Integer.parseInt(array[1])); + } + } // if (webAppInfo.getLoginConfig() != null && webAppInfo.getLoginConfig().getLoginPage().endsWith(".jsp")) { // servletRuntime.getServletContext().addJspFile("aaaaaa", webAppInfo.getLoginConfig().getLoginPage()); // } diff --git a/servlet-core/src/main/java/tech/smartboot/servlet/WebXmlParseEngine.java b/servlet-core/src/main/java/tech/smartboot/servlet/WebXmlParseEngine.java index 126269d..234876c 100644 --- a/servlet-core/src/main/java/tech/smartboot/servlet/WebXmlParseEngine.java +++ b/servlet-core/src/main/java/tech/smartboot/servlet/WebXmlParseEngine.java @@ -96,6 +96,7 @@ private Element commonParse(WebAppInfo webAppInfo, InputStream contextFile) thro Element parentElement = document.getDocumentElement(); webAppInfo.setMetadataComplete("true".equals(parentElement.getAttribute("metadata-complete"))); + webAppInfo.setVersion(parentElement.getAttribute("version")); parseBasicInfo(webAppInfo, parentElement); parseServlet(webAppInfo, parentElement); diff --git a/servlet-core/src/main/java/tech/smartboot/servlet/conf/DeploymentInfo.java b/servlet-core/src/main/java/tech/smartboot/servlet/conf/DeploymentInfo.java index c9b7e7e..22e818f 100644 --- a/servlet-core/src/main/java/tech/smartboot/servlet/conf/DeploymentInfo.java +++ b/servlet-core/src/main/java/tech/smartboot/servlet/conf/DeploymentInfo.java @@ -40,6 +40,8 @@ * @version V1.0 , 2019/12/11 */ public class DeploymentInfo { + private int effectiveMajorVersion; + private int effectiveMinorVersion; private final Map servlets = new HashMap<>(); private final List servletMappings = new ArrayList<>(); private final Map errorStatusPages = new HashMap<>(); @@ -324,5 +326,20 @@ public Set getSecurityRoles() { public void setDynamicListenerState(boolean dynamicListenerState) { this.dynamicListenerState = dynamicListenerState; } - + + public int getEffectiveMajorVersion() { + return effectiveMajorVersion; + } + + public void setEffectiveMajorVersion(int effectiveMajorVersion) { + this.effectiveMajorVersion = effectiveMajorVersion; + } + + public int getEffectiveMinorVersion() { + return effectiveMinorVersion; + } + + public void setEffectiveMinorVersion(int effectiveMinorVersion) { + this.effectiveMinorVersion = effectiveMinorVersion; + } } diff --git a/servlet-core/src/main/java/tech/smartboot/servlet/conf/WebAppInfo.java b/servlet-core/src/main/java/tech/smartboot/servlet/conf/WebAppInfo.java index 5ac966b..9cd7916 100644 --- a/servlet-core/src/main/java/tech/smartboot/servlet/conf/WebAppInfo.java +++ b/servlet-core/src/main/java/tech/smartboot/servlet/conf/WebAppInfo.java @@ -22,6 +22,7 @@ * @version V1.0 , 2019/12/12 */ public class WebAppInfo { + private String version; private String displayName; private String description; private boolean metadataComplete; @@ -190,4 +191,12 @@ public LoginConfig getLoginConfig() { public void setLoginConfig(LoginConfig loginConfig) { this.loginConfig = loginConfig; } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } } diff --git a/servlet-core/src/main/java/tech/smartboot/servlet/impl/ServletContextImpl.java b/servlet-core/src/main/java/tech/smartboot/servlet/impl/ServletContextImpl.java index f745b5f..81bc01a 100644 --- a/servlet-core/src/main/java/tech/smartboot/servlet/impl/ServletContextImpl.java +++ b/servlet-core/src/main/java/tech/smartboot/servlet/impl/ServletContextImpl.java @@ -120,13 +120,13 @@ public int getMinorVersion() { @Override public int getEffectiveMajorVersion() { - return 6; + return deploymentInfo.getEffectiveMajorVersion(); } @Override public int getEffectiveMinorVersion() { checkContextInitializeState(); - return 0; + return deploymentInfo.getEffectiveMinorVersion(); } @Override @@ -476,6 +476,7 @@ public FilterRegistration.Dynamic addFilter(String filterName, Class T createFilter(Class clazz) throws ServletException { + checkContextInitializeState(); return newInstance(clazz); }