Get the App
SLTechnology News&Howtos  ›  Servers  › 

Tomcat7 cooperates with redis to realize session sharing

Shulou Source: shulou.com Published: 2022-06-03 10:08:46 09月21日 Update

1. To install redis, it is relatively easy to check out the following blog

two。 Configure two Tomcat on this machine, which are tomcat7-8081 and tomcat7-8082.

Compile two index.jsp pages and put them in the tomcat7-8081\ webapps\ ROOT and tomcat7-8082\ webapps\ ROOT directories respectively. The contents of the index.jsp pages are as follows:

Get session id

Session Id:

#

Tomcat7-8081 access address: http://localhost:8081, browse display content: Session Id: ABA0CD68C927D855BD42A306AB17790C

Tomcat7-8082 access address: http://localhost:8082, browse display content: Session Id: A86BC413D12339380DD7B0079C50D9EB

Note: configure multiple Tomcat tutorials on the same server

3. Copy the jar required by tomcat

Copy the following jar to ${TOMCAT_HOME} / lib

Tomcat-redis-session-manager-VERSION.jar jedis-2.5.2.jar commons-pool2-2.2.jar

4. Configure tomcat

Edit ${TOMCAT_HOME} / conf/context.xml and add it to context

Where host and port are the ip and ports of redis

Now that the configuration is complete, tomcat uses redis to host session.

5. test

Note: tomcat needs to be restarted

Open the browser and enter http://localhost:8081 to enter.

Open the browser and enter http://localhost:8082 to enter.

The SESSIONID obtained is the same, which means it is successful, where ABA0CD68C927D855BD42A306AB17790C is SESSIONID.

Tags: Browse configure content two address copy browser page input success blog comments multiple that is tutorials servers directories ports compilation so far Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei Xiaomi NVidia Redmi