設置Cookie比這裏描述的要容易得多!我只舉一個例子:
//set a cookie
final TextBox t1 = new TextBox();
RootPanel.get().add(t1);
final TextBox t2 = new TextBox();
RootPanel.get().add(t2);
Button b1 = new Button("safe cookie");
b1.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// a cookie which expires after one week
Date now = new Date();
long nowLong = now.getTime();
nowLong = nowLong + (1000 * 60 * 60 * 24 * 7);// seven days
now.setTime(nowLong);
Cookies.setCookie(t1.getText(), t2.getText(), now);
//if the time isn't set it expires after the tab closes
}
});
RootPanel.get().add(b1);
//get a cookie
final TextBox t3 = new TextBox();
RootPanel.get().add(t3);
Button b2 = new Button("get cookie by name");
b2.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert(Cookies.getCookie(t3.getText()));
}
});
RootPanel.get().add(b2);
來源:Set Cookies with GWT applications to expire after expected time period,Class Cookies
[Google Gears已停用](http://en.wikipedia.org/wiki/Google_gears#End_of_life),所以我不認爲它是一個非常引人注目的選項。最好查看Cookie或Web存儲。 –