Package com.google.gwt.user.client
Class Cookies
java.lang.Object
com.google.gwt.user.client.Cookies
Provides access to browser cookies stored on the client. Because of browser
restrictions, you will only be able to access cookies associated with the
current page's domain.
-
Field Summary
Modifier and TypeFieldDescriptionCached copy of cookies.(package private) static String
Raw cookie string stored to allow cached cookies to be invalidated on write. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Gets the cookie associated with the given name.static Collection
<String> Gets the names of all cookies in this page's domain.static boolean
Gets the URIencode flag.static boolean
Checks whether or not cookies are enabled or disabled.(package private) static void
static void
removeCookie
(String name) Removes the cookie associated with the given name.static void
removeCookie
(String name, String path) Removes the cookie associated with the given name.static void
removeCookieNative
(String name, String path) Native method to remove a cookie with a path.static void
Sets a cookie.static void
Sets a cookie.static void
Sets a cookie.static void
setUriEncode
(boolean encode) Updates the URIencode flag and empties the cached cookies set.
-
Field Details
-
cachedCookies
Cached copy of cookies. -
rawCookies
Raw cookie string stored to allow cached cookies to be invalidated on write.
-
-
Method Details
-
getCookie
Gets the cookie associated with the given name.- Parameters:
name
- the name of the cookie to be retrieved- Returns:
- the cookie's value, or
null
if the cookie doesn't exist
-
getCookieNames
Gets the names of all cookies in this page's domain.- Returns:
- the names of all cookies
-
getUriEncode
public static boolean getUriEncode()Gets the URIencode flag. -
isCookieEnabled
public static boolean isCookieEnabled()Checks whether or not cookies are enabled or disabled.- Returns:
- true if a cookie can be set, false if not
-
removeCookie
Removes the cookie associated with the given name.- Parameters:
name
- the name of the cookie to be removed
-
removeCookie
Removes the cookie associated with the given name.- Parameters:
name
- the name of the cookie to be removedpath
- the path to be associated with this cookie (which should match the path given insetCookie(java.lang.String, java.lang.String)
)
-
removeCookieNative
Native method to remove a cookie with a path. -
setCookie
Sets a cookie. The cookie will expire when the current browser session is ended.- Parameters:
name
- the cookie's namevalue
- the cookie's value
-
setCookie
Sets a cookie.- Parameters:
name
- the cookie's namevalue
- the cookie's valueexpires
- when the cookie expires
-
setCookie
public static void setCookie(String name, String value, Date expires, String domain, String path, boolean secure) Sets a cookie. If uriEncoding is false, it checks the validity of name and value. Name: Must conform to RFC 2965. Not allowed: = , ; white space. Also can't begin with $. Value: No = or ;- Parameters:
name
- the cookie's namevalue
- the cookie's valueexpires
- when the cookie expiresdomain
- the domain to be associated with this cookiepath
- the path to be associated with this cookiesecure
-true
to make this a secure cookie (that is, only accessible over an SSL connection)
-
setUriEncode
public static void setUriEncode(boolean encode) Updates the URIencode flag and empties the cached cookies set. -
loadCookies
-