Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of Session conflicts between different ports of IP

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to solve the problem of Session conflict in different ports with IP". In daily operation, I believe many people have doubts about how to solve the problem of Session conflict in different ports with IP. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the question of "how to solve the problem of Session conflict in different ports with IP". Next, please follow the editor to study!

Multiple tomcat or weblogic are built on a server with different ports, and session is lost when starting access at the same time. For example, after logging in to visit An in the browser and opening a tab to access the B service in the browser, session is lost when you click on access A, and you need to log in to An again to access it. After searching the data, it is found that the problem is that IP thinks it is the same domain and receives the set-cookie instruction of B, covering the corresponding cookie content, including jsessionid, resulting in the loss of A's session. If the IP were different, this problem would not occur. Two session with the same IP have the same cookie, but unfortunately the sessionID is stored in the cookie, so when you visit A first and then B, the sessionid of B will overwrite the sessionid of A. There is no way to solve this problem, so don't have two ports, you'd better have two IP. It turns out that it is all caused by cookie, it will not distinguish between ports, resulting in a number of sites constantly covering the front, resulting in the loss of session.

Solution:

Method 1: deploy different application services in different virtual hosts or map different IP.

Method 2: corresponding tomcat service processing method: modify the name of the coocie to ensure that the cookie is not duplicated, that is, the jsessionid is not renamed to ensure that the sessioncookiename domain name is different under the same ip.

1. Tomcat5 modification method

Add the org.apache.catalina.SESSION_COOKIE_NAME parameter to the startup item

LinuxJAVA_OPTS='-Dorg.apache.catalina.SESSION_COOKIE_NAME=yousessionname'winset JAVA_OPTS= "- Dorg.apache.catalina.SESSION_COOKIE_NAME=yousessionname"

2. Tomcat6 and tomcat7 have the same modification method.

The added parameter of tomcat takes effect on all Context, so it can be set only for Context in later versions.

Add the sessionCookieName parameter to the Context container tag

I add that if it is Tomcat7 here, it is to add sessionCookieName= "yoursessionname" to the tag of the conf/context.xml file, and the test is valid.

3. Weblogic modification method

Set up each application to use a different cookie-name.

Settings for weblogic (set different cookie-name):

Please add the following code to WEB-INF\ Weblogic.xml

JSESSIONID1 at this point, the study on "how to solve the problem of Session conflicts with different ports of IP" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report