How to set cookie in another subdomain in JSP?

Cookies are stored under a domain name. For example, a cookie created with sub1.example.com/login.jsp can be saved in sub1.example.com or example.com strong>.

Can I save a cookie in sub2.example.com ?

+3
source share
1 answer

Give a cookie a domain name .example.com(pay attention to the leading point). Thus, a cookie is accessible under any subdomain. If you are going to share HttpSessionbetween subdomains, you can also simply configure the application server for this. It is best to refer to your documentation for details. In the case of, for example, Tomcat, just set the attribute emptySessionPath <Connector>to true:

<Connector emptySessionPath="true">
+2
source

Source: https://habr.com/ru/post/1729617/


All Articles