You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sai reddy <du...@gmail.com> on 2008/01/06 05:38:03 UTC

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

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......




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


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

Posted by Laurie Harper <la...@holoweb.net>.
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