Is calling
HttpServletResponse.addCookie();
(from servlet-api-2.5) multiple times using a cookie with the same name safe?
Safe in the sense of that there is a deterministic behavior, e.g. the subsequent calls will be ignored (the first wins) or the subsequent calls will always replace the cookie or something like that?
Example:
HttpServletResponse response = ...;
response.addCookie(new Cookie("foo", "bar"));
response.addCookie(new Cookie("foo", "42"));
Which value will be transferred to and stored by the browser?
Updated answer – as the comments from @skaffman and @Stephen C show this is not ideal practice.
The RFC Spec at http://www.ietf.org/rfc/rfc2109.txt states
On Tomcat server, the behaviour is the actual headers sent to the browser:
Here foo gets overwritten. Reading the cookie later gives you 42.