Control character in cookie value, consider BASE64 encoding your value, java operation cookie will report an error in Chinese, the report will report

Source: Internet
Author: User

Control character in cookie value, consider BASE64 encoding your value, java operation cookie will report an error in Chinese, the report will report

The project uses cookies to save Chinese characters, but the following error is reported:

Control character in cookie value, consider BASE64 encoding your value

It indicates that the value saved to the cookie has a control character and cannot be saved. But in fact the data does not have this problem. Looking at the following sentence, it seems that the value to be saved is base64 encoded. It may be because of garbled Characters During Chinese encoding, which may lead to some control characters. It seems that the setCookie method does not support saving the Chinese (GBK) encoding format.

Solution: encode the value to be saved using URLEncoder. encode (value, "UTF-8.

Decoding is also performed during extraction:

URLDecoder. decode (c. getValue (), "UTF-8 ");

 

PS. the same Code, I did not report an error in another project, check found that my another project database Save the format is UTF-8, so take it out can be used directly, the error is returned in GBK encoding. It seems that in JAVA Development, if you can use UTF-8 or use UTF-8 is better, must use Chinese (GBK), please be careful about Chinese garbled encoding problem.

Experience: Do not use GBK Chinese format for UTG-8 encoding. Do not save data in English.


Website login Error Control character in cookie value, consider BASE64 encoding your value
Encoding

To solve the base64 problem, go to GOOGLE search and find out --
Why is it easy to enter English --
Base64 encoding is not required for English

Related Article

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.