-1

enter image description here

enter image description here

How can I solve this problem,this is my first question in stack overflow.I really hope someone can give me some suggestions to solve this problem.

2 Answers2

0

Regarding future cookies, your solution is simply to URL-encode or Base64-encode the value before setting it in the cookie, and then URL-decode or Base64-decode it at read.

So, when creating the cookie do:

Cookie cookie = new Cookie(name, URLEncoder.encode(value, "UTF-8"));
Sarangan
  • 868
  • 1
  • 8
  • 24
0

Version 0 cookie values are restrictive in allowed characters. It only allows URL-safe characters. This covers among others the alphanumeric characters (a-z, A-Z and 0-9) and only a few lexical characters, including -, _, ., ~ and %. All other characters are invalid in version 0 cookies.

Your best bet is to URL-encode those characters. This way every character which is not allowed in URLs will be percent-encoded in this form %xx which is valid as cookie value.

So, when creating the cookie do:

Cookie cookie = new Cookie(name, URLEncoder.encode(value, "UTF-8"));
// ...

And when reading the cookie, do:

String value = URLDecoder.decode(cookie.getValue(), "UTF-8");
// ...

Refer to this link:

java.lang.IllegalArgumentException: Control character in cookie value or attribute

wuchunfu
  • 137
  • 9