Create a Cookie in JavaEE . I JSONObject and I do conversion to a string ( .toJSONString ).

Displays the following: java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value

Java 8, IDEA 2016 2.

  • What is in the cookie? - Komdosh
  • @Komdosh json object - {"dontRemember":false,"id":1,"categories":"unlock","hash":"0ab8c0e0cbc7ae1bce28d8b03c1b75b7"} - Tsyklop
  • hmm, everything seems to be in order, but an error, as I understand it, means that there is an unsupported character at position 34. Maybe there is a Russian letter e? - Komdosh
  • @Komdosh is not exactly Russian. - Tsyklop
  • @Komdosh Solved a problem. - Tsyklop 1:58 pm

1 answer 1

For creating:

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

For reading:

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

Taken from here