Search This Blog

GWT Example: set cookies

package test;

import com.google.gwt.user.client.Cookies;

public class CookieTest {

    public static final int COOKIE_EXPIRE_DAYS = 30;
    public static final long MILLISECS_PER_DAY = 1000L * 60L * 60L * 24L;

    public static void setMyCookie(String name, String value, int days) {

    if (value == null) {
        Cookies.removeCookie(name);
        return;
    }
        String v = Cookies.getCookie(name);
        if (value.equals(v)) {
            // Now
            Date d = new Date();
            // Now + days
            d.setTime(d.getTime() + MILLISECS_PER_DAY * days);
            Cookies.setCookie(name, value, d);
        }

    }

    public static void setMyCookie(String name, String value) {
            
            setCookie(name, value, COOKIE_EXPIRE_DAYS);
    }
}

No comments:

Post a Comment