{"id":276,"date":"2021-01-15T14:37:56","date_gmt":"2021-01-15T06:37:56","guid":{"rendered":"https:\/\/22pig.com\/?p=276"},"modified":"2022-10-28T23:02:22","modified_gmt":"2022-10-28T15:02:22","slug":"springmvc%e8%a7%a3%e5%86%b3%e8%b7%a8%e5%9f%9f%e9%97%ae%e9%a2%98%ef%bc%8c%e4%bb%a5%e5%8f%8a%e8%b7%a8%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%b0%83%e7%94%a8%e6%97%b6%e5%80%99session%e4%b8%a2%e5%a4%b1%e7%9a%84","status":"publish","type":"post","link":"http:\/\/22pig.com\/?p=276","title":{"rendered":"SpringMVC\u89e3\u51b3\u8de8\u57df\u95ee\u9898\uff0c\u4ee5\u53ca\u8de8\u670d\u52a1\u5668\u8c03\u7528\u65f6\u5019session\u4e22\u5931\u7684\u95ee\u9898\u603b\u7ed3\uff01\uff01\uff01"},"content":{"rendered":"<p>SpringMVC\u89e3\u51b3\u8de8\u57df\u95ee\u9898\uff0c\u4ee5\u53ca\u8de8\u670d\u52a1\u5668\u8c03\u7528\u65f6\u5019session\u4e22\u5931\u7684\u95ee\u9898\u603b\u7ed3\uff01\uff01\uff01<br \/>\n\u4ece2\u4e2a\u65b9\u9762\u89e3\u51b3<br \/>\n1\uff1aweb.xml\u914d\u7f6e\u4e2d\u52a0\u4e0a<br \/>\n<strong>&lt;filter&gt;<\/strong><br \/>\n<strong>&lt;filter-name&gt;CorsFilter&lt;\/filter-name&gt;<\/strong><br \/>\n<strong>&lt;filter-class&gt;org.apache.catalina.filters.CorsFilter&lt;\/filter-class&gt;<\/strong><br \/>\n<strong>&lt;init-param&gt;<\/strong><br \/>\n<strong>&lt;param-name&gt;cors.allowed.origins&lt;\/param-name&gt;<\/strong><br \/>\n<strong>&lt;param-value&gt;*&lt;\/param-value&gt;<\/strong><br \/>\n<strong>&lt;\/init-param&gt;<\/strong><br \/>\n<strong>&lt;init-param&gt;<\/strong><br \/>\n<strong>&lt;param-name&gt;cors.allowed.methods&lt;\/param-name&gt;<\/strong><br \/>\n<strong>&lt;param-value&gt;GET,POST,HEAD,OPTIONS,PUT&lt;\/param-value&gt;<\/strong><br \/>\n<strong>&lt;\/init-param&gt;<\/strong><br \/>\n<strong>&lt;init-param&gt;<\/strong><br \/>\n<strong>&lt;param-name&gt;cors.allowed.headers&lt;\/param-name&gt;<\/strong><br \/>\n<strong>&lt;param-value&gt;Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers&lt;\/param-value&gt;<\/strong><br \/>\n<strong>&lt;\/init-param&gt;<\/strong><br \/>\n<strong>&lt;init-param&gt;<\/strong><br \/>\n<strong>&lt;param-name&gt;cors.exposed.headers&lt;\/param-name&gt;<\/strong><br \/>\n<strong>&lt;param-value&gt;Access-Control-Allow-Origin,Access-Control-Allow-Credentials&lt;\/param-value&gt;<\/strong><br \/>\n<strong>&lt;\/init-param&gt;<\/strong><br \/>\n<strong>&lt;!&#8211; \u6b64\u5904\u4e00\u5b9a\u8981\u8fd9\u6837\u8bbe\u7f6e\uff0c\u800c\u4e14\u5bf9\u5e94\u7684\u5ba2\u6237\u7aef\u4e5f\u8981\u8bbe\u7f6exhrFields:{withCredentials:true},\u5426\u5219session\u5c06\u5931\u53bb &#8211;&gt;<\/strong><br \/>\n<em><strong>&lt;init-param&gt;<\/strong><\/em><br \/>\n<em><strong>&lt;param-name&gt;cors.support.credentials&lt;\/param-name&gt;<\/strong><\/em><br \/>\n<em><strong>&lt;param-value&gt;true&lt;\/param-value&gt;<\/strong><\/em><br \/>\n<em><strong>&lt;\/init-param&gt;<\/strong><\/em><br \/>\n<strong>&lt;init-param&gt;<\/strong><br \/>\n<strong>&lt;param-name&gt;cors.preflight.maxage&lt;\/param-name&gt;<\/strong><br \/>\n<strong>&lt;param-value&gt;10&lt;\/param-value&gt;<\/strong><br \/>\n<strong>&lt;\/init-param&gt;<\/strong><br \/>\n<strong>&lt;\/filter&gt;<\/strong><br \/>\n<strong>&lt;filter-mapping&gt;<\/strong><br \/>\n<strong>&lt;filter-name&gt;CorsFilter&lt;\/filter-name&gt;<\/strong><br \/>\n<strong>&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;<\/strong><br \/>\n<strong>&lt;\/filter-mapping&gt;<\/strong><br \/>\n&#8230;&#8230;..<\/p>\n<p><em>\u6ce8\u610f\uff1a\u6700\u4e3b\u8981\u7684\u662fcors.support.credentials\u8bbe\u7f6e\u4e3atrue<\/em><br \/>\n2\uff1ajquey\u5728\u4f7f\u7528ajax\u7684\u65f6\u5019\u4e00\u5b9a\u8981\u8bbe\u7f6e<br \/>\n<strong>xhrFields:{withCredentials:true}<\/strong><\/p>\n<p>\u51fa\u5904\uff1ahttps:\/\/blog.csdn.net\/cow5287687\/article\/details\/71216332<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SpringMVC\u89e3\u51b3\u8de8\u57df\u95ee\u9898\uff0c\u4ee5\u53ca\u8de8\u670d\u52a1\u5668\u8c03\u7528\u65f6\u5019session\u4e22\u5931\u7684\u95ee\u9898\u603b\u7ed3\uff01\uff01\uff01 \u4ece2\u4e2a\u65b9\u9762\u89e3\u51b3 1\uff1aweb.xml\u914d\u7f6e\u4e2d\u52a0\u4e0a &lt;filter&gt; &lt;filter-name&gt;CorsFilter&lt;\/filter-name&gt; &lt;filter-class&gt;org.apache.catalina.filters.CorsFilter&lt;\/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;cors.allowed.origins&lt;\/param-name&gt; &lt;param-value&gt;*&lt;\/param-value&gt; &lt;\/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;cors.allowed.methods&lt;\/param-name&gt; &lt;param-value&gt;GET,POST,HEAD,OPTIONS,PUT&lt;\/param-value&gt; &lt;\/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;cors.allowed.headers&lt;\/param-name&gt; &lt;param-value&gt;Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers&lt;\/param-value&gt; &lt;\/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;cors.exposed.headers&lt;\/param-name&gt; &lt;param-value&gt;Access-Control-Allow-Origin,Access-Control-Allow-Credentials&lt;\/param-value&gt; &lt;\/init-param&gt; &lt;!&#8211; \u6b64\u5904\u4e00\u5b9a\u8981\u8fd9\u6837\u8bbe\u7f6e\uff0c\u800c\u4e14\u5bf9\u5e94\u7684\u5ba2\u6237\u7aef\u4e5f\u8981\u8bbe\u7f6exhrFields:{withCredentials:true},\u5426\u5219session\u5c06\u5931\u53bb &#8211;&gt; &lt;init-param&gt; &lt;param-name&gt;cors.support.credentials&lt;\/param-name&gt; &lt;param-value&gt;true&lt;\/param-value&gt; &lt;\/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;cors.preflight.maxage&lt;\/param-name&gt; &lt;param-value&gt;10&lt;\/param-value&gt; &lt;\/init-param&gt; &lt;\/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;CorsFilter&lt;\/filter-name&gt; &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt; &lt;\/filter-mapping&gt; &#8230;&#8230;.. \u6ce8\u610f\uff1a\u6700\u4e3b\u8981\u7684\u662fcors.support.credentials\u8bbe\u7f6e\u4e3atrue 2\uff1ajquey\u5728\u4f7f\u7528ajax\u7684\u65f6\u5019\u4e00\u5b9a\u8981\u8bbe\u7f6e xhrFields:{withCredentials:true} \u51fa\u5904\uff1ahttps:\/\/blog.csdn.net\/cow5287687\/article\/details\/71216332<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,11],"tags":[],"class_list":["post-276","post","type-post","status-publish","format-standard","hentry","category-java","category-spring"],"_links":{"self":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=276"}],"version-history":[{"count":1,"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions"}],"predecessor-version":[{"id":736,"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts\/276\/revisions\/736"}],"wp:attachment":[{"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}