Top community members

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

Tomcat handle subdomains with 1 session error - java.lang.IllegalArgumentException: An invalid domain [.localhost] was specified for this cookie,

1 points
Asked by:
Ticket Ninja

I try to setup tomcat to handle subdomains with 1 session and got this error after I added new parameters to context.xml file in tomcat.


java.lang.IllegalArgumentException: An invalid domain [.localhost] was specified for this cookie

Context.xml file location:






<Context sessionCookiePath="/" sessionCookieDomain=".localhost">


How to solve this exception?

1 answers
3 points
Answered by:
Ticket Ninja

Quick fix:

<Context sessionCookiePath="/" sessionCookieDomain=".localhost">

  <!-- Use Legacy Cookie Processor, newer tomcat version implements Rfc6265 which causes our error -->
  <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />


We just need to tell tomcat to use LegacyCookieProcessor as newer tomcat version implements Rfc6265 specification which causes our error.

I don't know if browser will let you set JSESSIONID for localhost subdomains. For domain with sub-domains it will work.

For example when we use:


instead of .localhost then it will work and share JSESSIONID between all subdomains, eg:

  • etc

I found interesting articles, related to this topic:

0 comments Add comment

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey ūüĎč
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more