public class

Cookies

extends Object
java.lang.Object
   ↳ com.google.gwt.user.client.Cookies

Class Overview

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.

Summary

Public Methods
static String getCookie(String name)
Gets the cookie associated with the given name.
static Collection<String> getCookieNames()
Gets the names of all cookies in this page's domain.
static boolean getUriEncode()
Gets the URIencode flag.
static boolean isCookieEnabled()
Checks whether or not cookies are enabled or disabled.
static void removeCookie(String name, String path)
Removes the cookie associated with the given name.
static void removeCookie(String name)
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 setCookie(String name, String value, Date expires, String domain, String path, boolean secure)
Sets a cookie.
static void setCookie(String name, String value)
Sets a cookie.
static void setCookie(String name, String value, Date expires)
Sets a cookie.
static void setUriEncode(boolean encode)
Updates the URIencode flag and empties the cached cookies set.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static String getCookie (String name)

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

public static Collection<String> getCookieNames ()

Gets the names of all cookies in this page's domain.

Returns
  • the names of all cookies

public static boolean getUriEncode ()

Gets the URIencode flag.

public static boolean isCookieEnabled ()

Checks whether or not cookies are enabled or disabled.

Returns
  • true if a cookie can be set, false if not

public static void removeCookie (String name, String path)

Removes the cookie associated with the given name.

Parameters
name the name of the cookie to be removed
path the path to be associated with this cookie (which should match the path given in setCookie(String, String))

public static void removeCookie (String name)

Removes the cookie associated with the given name.

Parameters
name the name of the cookie to be removed

public static void removeCookieNative (String name, String path)

Native method to remove a cookie with a path.

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 name
value the cookie's value
expires when the cookie expires
domain the domain to be associated with this cookie
path the path to be associated with this cookie
secure true to make this a secure cookie (that is, only accessible over an SSL connection)

public static void setCookie (String name, String value)

Sets a cookie. The cookie will expire when the current browser session is ended.

Parameters
name the cookie's name
value the cookie's value

public static void setCookie (String name, String value, Date expires)

Sets a cookie.

Parameters
name the cookie's name
value the cookie's value
expires when the cookie expires

public static void setUriEncode (boolean encode)

Updates the URIencode flag and empties the cached cookies set.