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.