|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.http.Cookie
This class represents a "Cookie", as used for session management with HTTP and HTTPS protocols. Cookies are used to get user agents (web browsers etc) to hold small amounts of state associated with a user's web browsing. Common applications for cookies include storing user preferences, automating low security user signon facilities, and helping collect data used for "shopping cart" style applications.
Cookies are named, and have a single value. They may have optional attributes, including a comment presented to the user, path and domain qualifiers for which hosts see the cookie, a maximum age, and a version. Current web browsers often have bugs in how they treat those attributes, so interoperability can be improved by not relying on them heavily.
Cookies are assigned by servers, using fields added to HTTP response headers. In this API, cookies are saved one at a time into such HTTP response headers, using the javax.servlet.http.HttpServletResponse.addCookie method. User agents are expected to support twenty cookies per host, of at least four kilobytes each; use of large numbers of cookies is discouraged.
Cookies are passed back to those servers using fields added to HTTP request headers. In this API, HTTP request fields are retrieved using the cookie module's javax.servlet.http.HttpServletRequest.getCookies method. This returns all of the cookies found in the request. Several cookies with the same name can be returned; they have different path attributes, but those attributes will not be visible when using "old format" cookies.
Cookies affect the caching of the web pages used to set their values. At this time, none of the sophisticated HTTP/1.1 cache control models are supported by this class. Standard HTTP/1.0 caches will not cache pages which contain cookies created by this class.
Cookies are being standardized by the IETF. This class supports the original Cookie specification (from Netscape Communications Corp.) as well as the updated RFC 2109 specification. By default, cookies are stored using the original specification. This promotes maximal interoperability; an updated RFC will provide better interoperability by defining a new HTTP header field for setting cookies.
Constructor Summary | |
Cookie(java.lang.String name,
java.lang.String value)
Defines a cookie with an initial name/value pair. |
Method Summary | |
java.lang.Object |
clone()
Returns a copy of this object. |
java.lang.String |
getComment()
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined. |
java.lang.String |
getDomain()
Returns the domain of this cookie. |
int |
getMaxAge()
Returns the maximum specified age of the cookie. |
java.lang.String |
getName()
Returns the name of the cookie. |
java.lang.String |
getPath()
Returns the prefix of all URLs for which this cookie is targetted. |
boolean |
getSecure()
Returns the value of the 'secure' flag. |
java.lang.String |
getValue()
Returns the value of the cookie. |
int |
getVersion()
Returns the version of the cookie. |
void |
setComment(java.lang.String purpose)
If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment. |
void |
setDomain(java.lang.String pattern)
This cookie should be presented only to hosts satisfying this domain name pattern. |
void |
setMaxAge(int expiry)
Sets the maximum age of the cookie. |
void |
setPath(java.lang.String uri)
This cookie should be presented only with requests beginning with this URL. |
void |
setSecure(boolean flag)
Indicates to the user agent that the cookie should only be sent using a secure protocol (https). |
void |
setValue(java.lang.String newValue)
Sets the value of the cookie. |
void |
setVersion(int v)
Sets the version of the cookie protocol used when this cookie saves itself. |
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)
Names starting with a "$" character are reserved by RFC 2109.
name
- name of the cookievalue
- value of the cookieMethod Detail |
public void setComment(java.lang.String purpose)
getComment
public java.lang.String getComment()
setComment
public void setDomain(java.lang.String pattern)
getDomain
public java.lang.String getDomain()
setDomain
public void setMaxAge(int expiry)
getMaxAge
public int getMaxAge()
setMaxAge
public void setPath(java.lang.String uri)
getPath
public java.lang.String getPath()
setPath
public void setSecure(boolean flag)
getSecure
public boolean getSecure()
setSecure
public java.lang.String getName()
public void setValue(java.lang.String newValue)
With version zero cookies, you need to be careful about the kinds of values you use. Values with various special characters (whitespace, brackets and parentheses, the equals sign, comma, double quote, slashes, question marks, the "at" sign, colon, and semicolon) should be avoided. Empty values may not behave the same way on all browsers.
getValue
public java.lang.String getValue()
setValue
public int getVersion()
setVersion
public void setVersion(int v)
getVersion
public java.lang.Object clone()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |