一个响应中可以设置多少个 cookie?
How many cookies can be set in one response?
您可以在单个 http 响应上设置的 cookie 数量是否有上限?如果是,有多少?
因为我试图在一个响应中创建 2 个 cookie,由于某种原因只创建了一个。我正在使用下面的代码。
Cookie cookie = new Cookie("wNote", "1530571761964");
cookie.setMaxAge(2592000);
cookie.setPath("/myWebsite/");
response.addCookie(cookie);
另一个 cookie 是由服务器自动创建的 JSESSIONID
。在 Set-Cookie
下的响应 headers 我只能看到 JSESSIONID
.
- 阿帕奇 Tomcat 8.0.27
- Google Chrome 67.0
如果你用的是Tomcat那么,只有一个Cookie在HttpServletResponse.addCookie(javax.servlet.http.Cookie)但是这个方法可以调用多次:
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.
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
好的,请更深入地了解这个 cookie。我检查 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:
- at least 300 cookies
- at least 4096 bytes per cookie (as measured by the size of the
characters that comprise the cookie non-terminal in the syntax
description of the Set-Cookie header)
- at least 20 cookies per unique host or domain name
您可以在单个 http 响应上设置的 cookie 数量是否有上限?如果是,有多少?
因为我试图在一个响应中创建 2 个 cookie,由于某种原因只创建了一个。我正在使用下面的代码。
Cookie cookie = new Cookie("wNote", "1530571761964");
cookie.setMaxAge(2592000);
cookie.setPath("/myWebsite/");
response.addCookie(cookie);
另一个 cookie 是由服务器自动创建的 JSESSIONID
。在 Set-Cookie
下的响应 headers 我只能看到 JSESSIONID
.
- 阿帕奇 Tomcat 8.0.27
- Google Chrome 67.0
如果你用的是Tomcat那么,只有一个Cookie在HttpServletResponse.addCookie(javax.servlet.http.Cookie)但是这个方法可以调用多次:
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.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
好的,请更深入地了解这个 cookie。我检查 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:
- at least 300 cookies
- at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)
- at least 20 cookies per unique host or domain name