Bladeren bron

ServletUtil#getSession 方法不创建新 HttpSession

reghao 5 maanden geleden
bovenliggende
commit
467cda2393
1 gewijzigde bestanden met toevoegingen van 8 en 2 verwijderingen
  1. 8 2
      web/src/main/java/cn/reghao/jutil/web/ServletUtil.java

+ 8 - 2
web/src/main/java/cn/reghao/jutil/web/ServletUtil.java

@@ -104,7 +104,7 @@ public class ServletUtil {
     }
 
     public static HttpSession getSession() {
-        return getRequest().getSession();
+        return getRequest().getSession(false);
     }
 
     public static String getBody() throws IOException {
@@ -130,7 +130,13 @@ public class ServletUtil {
     }
 
     public static String getSessionId() {
-        return getRequest().getSession().getId();
+        String sessionId = "";
+        HttpSession httpSession = getRequest().getSession();
+        if (httpSession != null) {
+            sessionId = httpSession.getId();
+        }
+
+        return sessionId;
     }
 
     /**