Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format servlet cookie to http-friendly format [closed]

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!

like image 666
Jin Avatar asked Mar 23 '26 17:03

Jin


1 Answers

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.

like image 146
kaysush Avatar answered Mar 25 '26 07:03

kaysush