background
I have two projects projecta, projectb,projecta in Tomcata, PROJECTB in TOMCATB, Tomcata, TOMCATB on a server.
The root path of the project is mapped and can be accessed without project name, as follows
http://ip1:7777/
http://ip1:8080/ Problem
Log in at 7777 First, then log in at 8080, and find that the 7777-port user will be kicked down, and then at 7777, you will be kicked down by 8080. speculate
Because the session state is implemented by the jsessionid stored in cookies, the first instinct is that Jessionid is overwritten. Then, I did the following test;
8080 Port Refresh
Because this is the first request, the server side returns cookies
Name is Jsessionid, domain name is localhost, path is/
7777 Port Refresh
Request 7777, incredibly will be sent with a 8080-port cookie, 8080 of the SessionID in 7777 Tomcat must not find, so returned the new SessionID (name is jsessionid, domain name is localhost, path is/) , and then cover the SessionID of the 8080 generated.
We found the cause of the problem, because the SessionID of the two projects, the name, domain, path are the same, causing SessionID to be overwritten, resulting in the session invalidation, which also concluded that cookies are not differentiated port. Solve
There are three solutions for distinguishing paths, domain names, and names based on cookies.
Setting a domain name is different, such as
http://projectA.com:7777/
http://projectB.com:8080/
Set the path differently, set the project name, no longer map the root path, such as
Http://ip1:7777/projectA
Http://ip1:8080/projectB
Set key differently
Configure Sessioncookiename in Tomcat's Server.xml, as long as two different can
Tomcat Server.xml Context Configuration
Original address: Click on the Open link