{"id":318,"date":"2023-02-24T22:35:13","date_gmt":"2023-02-24T14:35:13","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=318"},"modified":"2023-04-30T14:56:34","modified_gmt":"2023-04-30T06:56:34","slug":"difference-between-several-acquisition-scenarios-in-springboot-request-getsession","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/24\/difference-between-several-acquisition-scenarios-in-springboot-request-getsession\/","title":{"rendered":"SpringBoot request.getSession()\u51e0\u79cd\u83b7\u53d6\u60c5\u51b5\u4e4b\u95f4\u7684\u5dee\u5f02"},"content":{"rendered":"<h3>\u4e09\u79cd\u60c5\u51b5\u5982\u4e0b<\/h3>\n<pre><code class=\"language-java\">HttpSession session = request.getSession();\n\nHttpSession session = request.getSession(true);\n\nHttpSession session = request.getSession(false);<\/code><\/pre>\n<p><!-- more --><\/p>\n<h3>\u4e09\u79cd\u60c5\u51b5\u4e4b\u95f4\u7684\u5dee\u5f02<\/h3>\n<p><code>getSession(boolean create)<\/code>\u610f\u601d\u662f\u8fd4\u56de\u5f53\u524dreqeust\u4e2d\u7684HttpSession\uff0c\u5982\u679c\u5f53\u524dreqeust\u4e2d\u7684HttpSession \u4e3anull\uff0c\u5f53create\u4e3atrue\uff0c\u5c31\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Session\uff0c\u5426\u5219\u8fd4\u56denull<\/p>\n<p>\u7b80\u800c\u8a00\u4e4b\uff1a<\/p>\n<p><code>HttpServletRequest.getSession(ture)<\/code>\u7b49\u540c\u4e8e <code>HttpServletRequest.getSession()<\/code><br \/>\n<code>HttpServletRequest.getSession(false)<\/code>\u7b49\u540c\u4e8e \u5982\u679c\u5f53\u524dSession\u6ca1\u6709\u5c31\u4e3anull\uff1b<\/p>\n<h3>\u5177\u4f53\u7684\u4f7f\u7528\u573a\u666f<\/h3>\n<p>\u5f53\u5411Session\u4e2d\u5b58\u53d6\u767b\u5f55\u4fe1\u606f\u65f6\uff0c\u4e00\u822c\u5efa\u8bae\uff1a<code>HttpSession session =request.getSession();<\/code><\/p>\n<p>\u5f53\u4eceSession\u4e2d\u83b7\u53d6\u767b\u5f55\u4fe1\u606f\u65f6\uff0c\u4e00\u822c\u5efa\u8bae\uff1a<code>HttpSession session =request.getSession(false);<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e09\u79cd\u60c5\u51b5\u5982\u4e0b HttpSession session = request.getSession(); Http [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[102],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-spring-boot","tag-session"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/318\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}