GXT中对Cookie的操作

在GXT中已经提供了相关的类,能够让我们很方便的操作cookies
就是下面这个
com.extjs.gxt.ui.client.state.CookieProvider
他有一个构造方法
  /**
   * Creates a new cookie provider
   * 
   * @param path The path for which the cookie is active (defaults to root '/'
   *          which makes it active for all pages in the site)
   *        激活此cookie的路径,默认使用/,即对所有页面有效
   * @param expires the cookie expiration date (defaults to 7 days from now)
   *        cookie的失效时间,默认一个星期
   * @param domain The domain to save the cookie for. Note that you cannot
   *          specify a different domain than your page is on, but you can
   *          specify a sub-domain.
   * @param secure <code>true</code> if the site is using SSL
   *        是否使用SSL安全连接
   */
  public CookieProvider(String path, Date expires, String domain, boolean secure) {
    this.path = path == null ? "/" : path;
    this.secure = secure;
    this.domain = domain;
    if (expires == null) {
      expires = new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 7)); //7-
                                                                            // days
    }
    this.expires = expires;
  }

你可以非常方便的设置和获取cookie值
  protected void setValue(String name, String value) {
    Cookies.setCookie(name, value, expires, domain, path, secure);
  }
  protected String getValue(String name) {
    return Cookies.getCookie(name);
  }


CookieProvider provider=new CookieProvider(null, null, null, false);
provider.set("name", "value");
provider.get("name");

你可能感兴趣的:(UI)