java - How do you update an existing cookie in JSP? -


i have cookie, mycookie, contains hash value. cookie set expire in 1 year , has path of '/'. need update cookie new hash value. when jsp script loaded retrieve cookie so:

cookie[] cookies = request.getcookies(); cookie mycookie = null;  (int = 0; < cookies.length; += 1) {   if (cookies[i].getname().equals("mycookie")) {     mycookie = cookies[i];     break;   } } 

after determining value of cookie needs updated, following update it:

mycookie.setvalue("my new value"); response.addcookie(mycookie); 

examining results, have 2 instances of mycookie: original version correct expiration date , path, , old, invalid, value; , new cookie named "mycookie" expires @ end of session, correct value, , path of jsp document.

if do:

mycookie.setvalue("my new value"); mycookie.setpath(mycookie.getpath()); mycookie.setmaxage(mycookie.getmaxage()); response.addcookies(mycookie); 

the same thing happens. 2 cookies same name , different properties.

does cookie object not retain properties when retrieved? how can update cookie?

note: not want modify path or expiration date. want update value of set cookie.

per section 3.3.4 of rfc 2965, user agent not include expiration information in cookie header sent server. therefore, there no way update existing cookie's value while retaining expiration date set based solely on information associated cookie.

so answer question is: can't that.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -