本文转载自:http://lavasoft.blog.51cto.com/62575/78163
HttpServletResponse.addCookie(javax.servlet.http.Cookie)
method, which adds fields to HTTP response headers to send cookies to the browser, one at a time. The browser is expected to support 20 cookies for each Web server, 300 cookies total, and may limit cookie size to 4 KB each.
HttpServletResponse.addCookie(javax.servlet.http.Cookie)
方法,一个浏览器预计最多可支持300个cookie,对一个站点最多支持20个cookie,并且可能限制一个cookie的大小不超过4KB。
HttpServletRequest.getCookies()
method. Several cookies might have the same name but different path attributes.
HttpServletRequest.getCookies()
中重新获取到。
Constructor Summary |
Cookie(java.lang.String name, java.lang.String value) Constructs a cookie with a specified name and value. 使用指定的名称和值构建一个cookie。 |
Method Summary | |
java.lang.Object |
clone() Overrides the standard java.lang.Object.clone method to return a copy of this cookie. 返回cookie克隆的副本,这个方法覆盖了java.lang.Object.clone ()方法。 |
java.lang.String |
getComment() Returns the comment describing the purpose of this cookie, or null if the cookie has no comment.返回一个描述cookie用途的注释,如果没有注释,则返回null。 |
java.lang.String |
getDomain() Returns the domain name set for this cookie.返回一个cookie域名。(域名指定cookie在哪个域中有效,例如:Domain=.blog.51cto.com) |
int |
getMaxAge() Returns the maximum age of the cookie, specified in seconds, By default, -1 indicating the cookie will persist until browser shutdown. 返回cookie在客户端最大的有效时间,以秒为单位。默认情况下为-1,表示cookie将一直有效直到浏览器关闭。 |
java.lang.String |
getName() Returns the name of the cookie.返回cookie的名字。 |
java.lang.String |
getPath() Returns the path on the server to which the browser returns this cookie.返回cookie对服务器上哪个url有效。 |
boolean |
getSecure() Returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol. 如果浏览器仅仅安全协议下发送cookie则返回true。浏览器能使用任何协议发送cookie则返回fasle。 |
java.lang.String |
getValue() Returns the value of the cookie. 返回cookie的值。 |
int |
getVersion() Returns the version of the protocol this cookie complies with.返回cookie内容所遵循的版本。(目前只有值为1时可用)。 |
void |
setComment(java.lang.String purpose) Specifies a comment that describes a cookie's purpose.设置描述cookie用途的注释。 |
void |
setDomain(java.lang.String pattern) Specifies the domain within which this cookie should be presented.设置cookie在哪一个域中使用。 |
void |
setMaxAge(int expiry) Sets the maximum age of the cookie in seconds.设置cookie最大的有效时间。 |
void |
setPath(java.lang.String uri) Specifies a path for the cookie to which the client should return the cookie.设置cookie的有效路径。 |
void |
setSecure(boolean flag) Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.设置是否使用安全协议如HTTPS或SSL等发送cookie。 |
void |
setValue(java.lang.String newValue) Assigns a new value to a cookie after the cookie is created. 给一个cookie重新指定一个新值。 |
void |
setVersion(int v) Sets the version of the cookie protocol this cookie complies with.设置cookie使用的协议版本。 |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Cookie(java.lang.String name, java.lang.String value)
setValue
method.
setValue
方法来改变。
setVersion
method.
setVersion
来改变。
name
- a
String
specifying the name of the cookie 一个指定cookie名字的字符串。
value
- a
String
specifying the value of the cookie 一个指定cookie值的字符串。
setValue(java.lang.String)
,
setVersion(int)
Method Detail |
public void setComment(java.lang.String purpose)
purpose
- a
String
specifying the comment to display to the user
getComment()
public java.lang.String getComment()
null
if the cookie has no comment.
String
containing the comment, or
null
if none
setComment(java.lang.String)
public void setDomain(java.lang.String pattern)
.foo.com
) and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone (for example,
[url]www.foo.com[/url]
, but not
a.b.foo.com
). By default, cookies are only returned to the server that sent them.
.foo.com
),并且意味着这个cookie在指定的域名系统(DNS)下是有效的,比如(
[url]www.foo.com[/url]
,但不是
a.b.foo.com
)。默认情况下,cookie仅能返回给发送他们的服务器。
pattern
- a
String
containing the domain name within which this cookie is visible; form is according to RFC 2109
getDomain()
public java.lang.String getDomain()
String
containing the domain name
setDomain(java.lang.String)
public void setMaxAge(int expiry)
expiry
- an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie
getMaxAge()
public int getMaxAge()
-1
indicating the cookie will persist until browser shutdown.
setMaxAge(int)
public void setPath(java.lang.String uri)
uri
- a
String
specifying a path
getPath()
public java.lang.String getPath()
String
specifying a path that contains a servlet name, for example,
/catalog
setPath(java.lang.String)
public void setSecure(boolean flag)
false
. 默认值是false。
flag
- if
true
, sends the cookie from the browser to the server only when using a secure protocol; if
false
, sent on any protocol
getSecure()
public boolean getSecure()
true
if the browser is sending cookies only over a secure protocol, or
false
if the browser can send cookies using any protocol.
true
if the browser uses a secure protocol; otherwise,
true
setSecure(boolean)
public java.lang.String getName()
String
specifying the cookie's name
public void setValue(java.lang.String newValue)
newValue
- a
String
specifying the new value
getValue()
,
Cookie
public java.lang.String getValue()
String
containing the cookie's present value
setValue(java.lang.String)
,
Cookie
public int getVersion()
setVersion(int)
public void setVersion(int v)
v
- 0 if the cookie should comply with the original Netscape specification; 1 if the cookie should comply with RFC 2109
getVersion()
public java.lang.Object clone()
java.lang.Object.clone
method to return a copy of this cookie.
java.lang.Object.clone
()方法。