Session is lost and created as new in every servlet request

One possible cause for this is having a “naked” host name (i.e. one without a domain part). That’s fairly common if you’re working in an Intranet.

The problem is that almost all browsers cookies will not accept cookies for hostnames without a domain name. That’s done in order to prevent evilsite.com from setting a Cookie for com (which would be bad, as it would be the ultimate tracking cookie).

So if you access your applicaton via http://examplehost/ it won’t accept any cookie, while for http://examplehost.localdomain/ it will accept (and return) the cookie just fine.

The nasty thing about that is that the server can’t distinguish between “the browser got the cookie and ignored it” and “the browser never got the cookie”. So each single access will look like a completely new sesson to the server.

Leave a Comment