Cookie cannot be saved in Chinese

Source: Internet
Author: User
Zookeeper

When saving username with a cookie, the cookie value cannot be saved in Chinese, and the following error is reported:

Control Character in cookie value, consider base64 encoding your value

The following error occurs: Response. addcookie (cookie );

This problem has also been encountered in programming, mainly because of the number of illegal tokens in the cookie value, this error is reported if characters such as "\ r \ n" and "\ n" exist, but I am a username. It does not exist, I set the cookie value to a default Chinese username. If the execution result is correct, the same error occurs. The result shows that Chinese characters cannot be saved in the cookie.

Finally think about converting Chinese to UTF-8 string to save should be no problem, that is, using urlencoder. encode ("Chinese username", "UTF-8"); this converts the Chinese username to a UTF-8 string, when executed. At the end of receiving this value, use urldecoder. Decode (cookies. getvalue (), "UTF-8"); to decode the Chinese username I want.
Urlencode and urldecode are included in the java.net package.

Cookie cannot be saved in Chinese

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.