{"id":1579,"date":"2015-03-23T18:12:25","date_gmt":"2015-03-23T17:12:25","guid":{"rendered":"http:\/\/codingexplained.com\/?p=1579"},"modified":"2015-03-23T18:10:28","modified_gmt":"2015-03-23T17:10:28","slug":"tomcat-share-session-cookies-subdomains","status":"publish","type":"post","link":"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains","title":{"rendered":"Share Session Cookies between Subdomains with Tomcat"},"content":{"rendered":"<p class=\"p1\">In order to share session cookies between subdomains in your Java web application hosted with Apache Tomcat, you need to make a simple configuration change. What you simply need to do is to make a small change to your web application&#8217;s context. You might have more than one context if you have more than one web application hosted by your Tomcat web server. In my case, I have <a title=\"Installing Tomcat 8 on OS X Yosemite\" href=\"\/operating-systems\/mac\/installing-tomcat-8-os-x-yosemite\">installed Tomcat on OS X<\/a>, and therefore I need to change\u00a0<span class=\"code\">\/Library\/Tomcat\/conf\/context.xml<\/span>. Note that the path to your Tomcat installation may differ depending on how you installed Tomcat and which platform you are running Tomcat on.<\/p>\n<p class=\"p1\">Nevertheless, once you have found the appropriate context, then you need to add the\u00a0<span class=\"code\">sessionCookieDomain<\/span> attribute to the context&#8217;s root node. The value should be the domain name that you use to access your web application, <strong>prepended by a period<\/strong>.<\/p>\n<pre>\r\n<code>\r\n&lt;Context sessionCookieDomain=&quot;.example.com&quot;&gt;\r\n\t&lt;!-- ... --&gt;\r\n&lt;\/Context&gt;\r\n<!--formatted--><\/code>\r\n<\/pre>\n<p>If you are not accessing your web application with a domain name, then you should add the below to your <span class=\"code\">\/etc\/hosts<\/span> file (for UNIX-based environments &#8211; the path is obviously different on Windows).<\/p>\n<pre>\r\n<code>\r\n127.0.0.1\texample.com\r\n127.0.0.1\tsubdomain1.example.com\r\n127.0.0.1\tsubdomain2.example.com\r\n127.0.0.1\tsubdomain3.example.com\r\n<\/code>\r\n<\/pre>\n<p>Now, save the file and restart Tomcat.<\/p>\n<pre>\r\n<code>\r\ncd \/path\/to\/tomcat\/bin\r\n.\/catalina.sh stop\r\n.\/catalina.sh start\r\n<\/code>\r\n<\/pre>\n<p>Your web application&#8217;s session cookies should now be shared across subdomains. Please note that the <span class=\"code\">sessionCookieDomain<\/span> attribute requires a Tomcat version of at least 6.0.27.<\/p>\n<p>Now, in case you have more than one context (i.e. more than one web application), and you want to share session cookies between those as well, then you also have to set the <span class=\"code\">sessionCookiePath<\/span> to <span class=\"code\">\/<\/span>, like so:<\/p>\n<pre>\r\n<code>\r\n&lt;Context sessionCookieDomain=&quot;.example.com&quot; sessionCookiePath=&quot;\/&quot;&gt;\r\n\t&lt;!-- ... --&gt;\r\n&lt;\/Context&gt;\r\n<\/code>\r\n<\/pre>\n<p>Thank you for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In order to share session cookies between subdomains in your Java web application hosted with Apache Tomcat, you need to make a simple configuration change. What you simply need to do is to make a small change to your web application&#8217;s context. You might have more than one context if you have more than one&hellip; <a href=\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains\" class=\"more-link\">read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[8],"tags":[42,115,116],"series":[],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Share Session Cookies between Subdomains with Tomcat<\/title>\n<meta name=\"description\" content=\"Sharing session cookies between subdomains with Tomcat can easily be enabled by using the sessionCookieDomain attribute in the context configuration.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Share Session Cookies between Subdomains with Tomcat\" \/>\n<meta property=\"og:description\" content=\"Sharing session cookies between subdomains with Tomcat can easily be enabled by using the sessionCookieDomain attribute in the context configuration.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains\" \/>\n<meta property=\"og:site_name\" content=\"Coding Explained\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codingexplained\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codingexplained\" \/>\n<meta property=\"article:published_time\" content=\"2015-03-23T17:12:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-03-23T17:10:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codingexplained.com\/wp-content\/uploads\/2015\/11\/codingexplained-fb-promote.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"444\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bo Andersen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codingexplained\" \/>\n<meta name=\"twitter:site\" content=\"@codingexplained\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bo Andersen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains\",\"url\":\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains\",\"name\":\"Share Session Cookies between Subdomains with Tomcat\",\"isPartOf\":{\"@id\":\"https:\/\/codingexplained.com\/#website\"},\"datePublished\":\"2015-03-23T17:12:25+00:00\",\"dateModified\":\"2015-03-23T17:10:28+00:00\",\"author\":{\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d\"},\"description\":\"Sharing session cookies between subdomains with Tomcat can easily be enabled by using the sessionCookieDomain attribute in the context configuration.\",\"breadcrumb\":{\"@id\":\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codingexplained.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Share Session Cookies between Subdomains with Tomcat\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codingexplained.com\/#website\",\"url\":\"https:\/\/codingexplained.com\/\",\"name\":\"Coding Explained\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codingexplained.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d\",\"name\":\"Bo Andersen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g\",\"caption\":\"Bo Andersen\"},\"description\":\"I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!\",\"sameAs\":[\"https:\/\/codingexplained.com\",\"https:\/\/www.facebook.com\/codingexplained\",\"https:\/\/www.linkedin.com\/in\/ba0708\",\"https:\/\/twitter.com\/codingexplained\",\"https:\/\/www.youtube.com\/c\/codingexplained\"],\"url\":\"https:\/\/codingexplained.com\/author\/andy\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Share Session Cookies between Subdomains with Tomcat","description":"Sharing session cookies between subdomains with Tomcat can easily be enabled by using the sessionCookieDomain attribute in the context configuration.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains","og_locale":"en_US","og_type":"article","og_title":"Share Session Cookies between Subdomains with Tomcat","og_description":"Sharing session cookies between subdomains with Tomcat can easily be enabled by using the sessionCookieDomain attribute in the context configuration.","og_url":"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains","og_site_name":"Coding Explained","article_publisher":"https:\/\/www.facebook.com\/codingexplained","article_author":"https:\/\/www.facebook.com\/codingexplained","article_published_time":"2015-03-23T17:12:25+00:00","article_modified_time":"2015-03-23T17:10:28+00:00","og_image":[{"width":1200,"height":444,"url":"https:\/\/codingexplained.com\/wp-content\/uploads\/2015\/11\/codingexplained-fb-promote.png","type":"image\/png"}],"author":"Bo Andersen","twitter_card":"summary_large_image","twitter_creator":"@codingexplained","twitter_site":"@codingexplained","twitter_misc":{"Written by":"Bo Andersen","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains","url":"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains","name":"Share Session Cookies between Subdomains with Tomcat","isPartOf":{"@id":"https:\/\/codingexplained.com\/#website"},"datePublished":"2015-03-23T17:12:25+00:00","dateModified":"2015-03-23T17:10:28+00:00","author":{"@id":"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d"},"description":"Sharing session cookies between subdomains with Tomcat can easily be enabled by using the sessionCookieDomain attribute in the context configuration.","breadcrumb":{"@id":"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codingexplained.com\/coding\/java\/tomcat-share-session-cookies-subdomains#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codingexplained.com\/"},{"@type":"ListItem","position":2,"name":"Share Session Cookies between Subdomains with Tomcat"}]},{"@type":"WebSite","@id":"https:\/\/codingexplained.com\/#website","url":"https:\/\/codingexplained.com\/","name":"Coding Explained","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codingexplained.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d","name":"Bo Andersen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codingexplained.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g","caption":"Bo Andersen"},"description":"I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!","sameAs":["https:\/\/codingexplained.com","https:\/\/www.facebook.com\/codingexplained","https:\/\/www.linkedin.com\/in\/ba0708","https:\/\/twitter.com\/codingexplained","https:\/\/www.youtube.com\/c\/codingexplained"],"url":"https:\/\/codingexplained.com\/author\/andy"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3mJkW-pt","_links":{"self":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/1579"}],"collection":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/comments?post=1579"}],"version-history":[{"count":5,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/1579\/revisions"}],"predecessor-version":[{"id":1617,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/1579\/revisions\/1617"}],"wp:attachment":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/media?parent=1579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/categories?post=1579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/tags?post=1579"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/series?post=1579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}