Create Cookie throws Exception: Java.lang.IllegalArgumentException:Control character in cookie value

Source: Internet
Author: User

The constructor of the cookie object is called to create a cookie. The constructor of a cookie object has two string arguments: The cookie name and the cookie value.
Neither the name nor the value can contain white space characters and the following characters: [] () < > =, "/? @ : ;

The error is in Response.addcookie (cookie);//cookie is a cookie instance.

In the Java EE doc, the cookies only support ASCII characters and cannot have commas, semicolons,
Blank. or start with $. The name cannot be changed after it is created. If you want to store Chinese, first use Urlecode encoding, in the deposit, remove the time, with decode decoding.

Encode the value before saving the cookie:

Urlencoder.encode (Cookievalue, "UTF-8");

Decoding when the cookie value is taken:

Urldecoder.decode (Localcookievalue, "UTF-8");

Create Cookie throws Exception: Java.lang.IllegalArgumentException:Control character in cookie value

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.