How many cookies can be set in one response?

Multi tool use
How many cookies can be set in one response?
Is there a maximum number of cookies which you can set on a single http response? If yes how many?
Because I'm trying to create 2 cookies in one response, for some reason only one is getting created. I'm using the code below.
Cookie cookie = new Cookie("wNote", "1530571761964");
cookie.setMaxAge(2592000);
cookie.setPath("/myWebsite/");
response.addCookie(cookie);
the other cookie is the JSESSIONID
which is being created by the server automatically. In the response headers under Set-Cookie
I can see only JSESSIONID
.
JSESSIONID
Set-Cookie
JSESSIONID
1 Answer
1
If you are using Tomcat then, only one Cookie in HttpServletResponse.addCookie(javax.servlet.http.Cookie) But this method can call multiple times:
The servlet sends cookies to the browser by using the HttpServletResponse.addCookie(javax.servlet.http.Cookie)
method, which adds fields to HTTP response headers to send cookies to the browser, one at a time.
HttpServletResponse.addCookie(javax.servlet.http.Cookie)
This method can be called multiple times to set more than one cookie.
The browser is expected to support 20 cookies for each Web server, 300 cookies total, and may limit cookie size to 4 KB each.
Cookies Doc
Ok going more deeper about this cookies. I check the RFC 2109
Practical user agent implementations have limits on the number and
size of cookies that they can store. In general, user agents' cookie
support should have no fixed limits. They should strive to store as
many frequently-used cookies as possible. Furthermore, general-use
user agents should provide each of the following minimum capabilities
individually, although not necessarily simultaneously:
This method can be called multiple times to set more than one cookie
@stdunbar You are correct it was confusing I edited the answer. YOu can only one Cookie in the servlet Response but you can call multiple Times.
– Gatusko
Jul 3 at 21:09
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I'm confused by this answer - the Javadoc specifically says
This method can be called multiple times to set more than one cookie
. So with standard Java EE there is not set limit. This has nothing directly to do with Tomcat.– stdunbar
Jul 3 at 21:05