TOMCAT7 shared level two domain session settings

Source: Internet
Author: User

Requirements:

Tomcat deploys an application that requires all level two domain names to share the same session

Cases:

Existing two domain names

A.abc.com

B.abc.com

A.abc.com session.setattribute ("Test", "test123");

B.abc.com in Session.getattribute ("test"); Can get to test123

Also saw a lot of articles on the Internet, basically are to modify Tomcat source code, or use MSM (memcached persistence session), but are not what I want ....

Solution:

set server.xml in 1.tomcat7

<context reloadable= "false" path= "/"  docbase= "D:\workspace\project\WebContent"
    sessioncookiepath= "/" Sessioncookiedomain= "abc.com" sessioncookiename= "Jsessionid"/>

Mainly here: path= "/" sessioncookiepath= "/" sessioncookiedomain= "abc.com" sessioncookiename= "Jsessionid"

Can be shared under the abc.com domain name SessionID

When access to a.abc.com gets SessionID, the same browser does not generate a new SessionID in the access b.abc.com, which guarantees a.abc.com login authorization SessionID can also be used under b.abc.com

2. Jump Request

Add <a href= ' http://b.abc.com/action ' >action</a> in a.abc.com page a.html

This background receives the request by default carries the SessionID, because through the above setting foreground's cookie scope already is the entire abc.com, this does not have the question

3.ajax Request

Using AJAX requests Http://b.abc.com/action inaccessible in a.abc.com page a.html, each request generates a new SessionID

Because there is cross-domain access, JS Cross-domain problem See here

$.ajax ({
URL: "Http://b.abc.com/action",
DataType: "Jsonp",
Success:function (res) {
Console.log (RES);
}
});

This will be able to reach the level two domain share session.

Why do you need to share two-level domain name access to such features.

when a page requires a large number of concurrent requests, the browser can handle only 6 requests at a time

For example, on the page, send 100 requests at a time, each request to the background after sleep 10s

the result of using the Firefox page is that all requests have been sent, but only 6 requests have reached the background, leaving 94 requests in the blocking state, using Firebug to see

The blocking state precedes the domain name resolution, that is, the request was not sent at all.

this will greatly affect the loading speed of our pages, so we need to use multiple level two domain names to accept the request.

PS: In this case, Tomcat is one that can be matched with Memcached+nginx to complete Tomcat's distributed settings.

use MSM to complete session persistence, with multiple domain name nodes. Speed-Leveraging O (∩_∩) o~

Taobao loading pictures are also used in a similar way

Get Tb1wdmvgvxxxxa0xfxxuakpjpxx-90-90.png
OK
Gtms01.alicdn.com
13.6 KB
103.243.139.140:80

39ms


Get Tb1d0ingvxxxxxwxfxxkpoy1pxx-108-220.png
OK
Gtms03.alicdn.com
16.6 KB
103.243.139.150:80

62ms


Get Tb18ppbhxxxxxxtxxxxkpoy1pxx-108-220.png
OK
Gtms01.alicdn.com
18.5 KB
103.243.139.140:80

89ms


Get Tb1tagggvxxxxxaxpxxkpoy1pxx-108-220.png
OK
Gtms04.alicdn.com
43.4 KB
103.243.139.150:80

49ms


Get Tb1ld5pgvxxxxbhxfxxkpoy1pxx-108-220.png
OK
Gtms02.alicdn.com
15.2 KB
103.243.139.150:80

154ms


Get Tb1hfnahxxxxxa1xxxxwu0bfxxx.png
OK
Gtms02.alicdn.com
14.0 KB
103.243.139.150:80

95ms


Get TB1Jq.VGVXXXXbzXXXXwu0bFXXX.png
OK
Gtms03.alicdn.com
14.4 KB
103.243.139.150:80

41ms


Get tb22mgmbxxxxxajxxxxxxxxxxxx_!! 100008692.jpg
OK
Img03.taobaocdn.com
7.8 KB
125.39.199.40:80

64ms


Get tb1ujk1gvxxxxbgxxxxsutbfxxx.jpg
OK
Gtms04.alicdn.com
3.1 KB
103.243.139.150:80

32ms


Get Tb1oqiggvxxxxbcxfxxaqx0txxx-200-50.jpeg
OK
Gtms02.alicdn.com
4.9 KB
103.243.139.150:80

52ms


Get tb154qwgvxxxxx0xxxxsutbfxxx.jpg
OK
Gtms04.alicdn.com
2.4 KB
103.243.139.150:80

54ms


Get Tb1htmzgvxxxxbjaxxxuakpjpxx-90-90.png
OK
Gtms01.alicdn.com
5.7 KB
103.243.139.140:80



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.