Use Cookie in java to replace Session to solve the problem of cross-domain Session failure

Source: Internet
Author: User

In a distributed system, session failure occurs during cross-origin access of subdomains, resulting in logon failure.

For example, if a user successfully logs on to www.111cn.net but fails to switch to its personalized domain name mb.111cn.net, the session fails.

What should I do?

You can use the session replication scheme, such as nfs session sharing, membercache session storage, and terracotta.
The above solutions can be used, but the above solutions will lead to a complicated development environment and an O & M environment, and slow session response across networks.
Therefore, we have used a lightweight cookie to replace the session solution.

The Cookie replaces the Session and solves the problem of distributed Session failure as follows:

Stored Procedure:
1. Convert the javabean to be saved to a json string (using the gson tool)
2. des encrypted json string
3. Set it to the cookie of the root domain name
Cookie. setDomain ("kaihuangzhe.com ");

Resolution process:
1. Traverse all cookies
2. Find the corresponding cookie
3. des decrypts the json string
4. Restore to javabean (gson ).

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.