You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Laurie Harper <la...@holoweb.net> on 2008/01/08 23:11:06 UTC

Re: How to set multiple cookies to access them using bean:cookie multiple="yes" tag.

sai reddy wrote:
> I'm a newbie to struts. I wanted to practice <bean:cookie> tag's 
> 'multiple' attribute.
> But the problem is i don't know how to set multiple cookies.
> Please help me.
> 
> I tried this code to set multiple cookies.......but only the last
> cookie gets added.......i mean the first one gets replaced by the
> second cookie resulting in only one cookie set at the end.
> 
> ##################################################################
> ##    response.addCookie(new Cookie("animal","dog"));        ##
> ##    response.addCookie(new Cookie("animal","cat"));        ##
> ##################################################################
> 
> Please tell me how to set multiple cookies......

You can't have multiple cookies with the same name. Either name each 
cookie differently or, if you want a single cookie with multiple values, 
you will need to explicitly combine them into a single value (e.g. by 
encoding them as a comma separated list). The code above is just saying 
"set the value of the 'animal' cookie 'dog', then *reset* it to 'cat'".

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org