瀏覽代碼

ServletUtil#getSession 方法不创建新 HttpSession

reghao 5 月之前
父節點
當前提交
467cda2393
共有 1 個文件被更改,包括 8 次插入2 次删除
  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;
     }
 
     /**