Given a javax.servlet.http.Cookie object, is there a method somewhere that can format the cookie to http friendly format so I can send it in the response? Likewise, given a cookie header in request, is there a method to parse the cookie into a javax.servlet.http.Cookie object? I've looked all over but couldn't find a method that does that.
Thanks!
You can use HttpCookie class for your own implementation. Use its toString() function to
Constructs a cookie header string representation of this cookie, which is in the format defined by corresponding cookie specification, but without the leading "Cookie:" token.
After this add header Set-Cookie:THE_TO_STRING_VALUE to the response and that's it.
For reading the cookies back you need to parse the headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With