0

I am trying to figure out how to remove beginning and end quotes from a cookie value. I create the cookie like this:

String value = "qj.w&idjqDJWIj2i0292-/2l2==2-;2;2";

// Cookie belongs to javax.servlet.http.Cookie
Cookie cookie = new Cookie("TestCookie", value);

Then I add it to my HttpServletResponse object by doing response.addCookie(cookie). When I look at the cookie in my browser (Chrome), the cookie value has quotes around it.

How do I get rid of the quotes? I tried doing

value = value.replaceAll("^\"|\"$", "");

However, that didn't help me, which makes sense as there are no quotes in the original String, so something in the Cookie class is adding them.

Please note, I cannot encode it as I want the String to stay as is. Encoding changes some of the characters.

Any information would be appreciated.

o.o
  • 3,563
  • 9
  • 42
  • 71
  • 2
    Are you sure Chrome didn’t add the quotes for display purposes? – VGR Jan 09 '18 at 19:49
  • I'm pretty sure. The other cookies I look at that are set do not have quotes around them. And the purpose of the cookie I am trying to set is not working. – o.o Jan 09 '18 at 19:56

0 Answers0