2

我正在尝试通过以下方法获取 CookieProvider 的值:

public void getValue(){
    StateManager.get().get("idReg", String.class, new Callback<String, Throwable>() {            
    public void onFailure(Throwable reason) {
        state = "";
    }
    public void onSuccess(String result) {
    state = result; 
        });    
}

发出以下异常:

java.lang.NullPointerException at
com.google.web.bindery.autobean.gwt.client.impl.JsniCreatorMap$.create$(JsniCreatorMap.java:44) 
at com.google.web.bindery.autobean.gwt.client.impl.AbstractAutoBeanFactory.     
create(AbstractAutoBeanFactory.java:38) at    
com.sencha.gxt.state.client.StateManager.getDefaultStateInstance(StateManager.java:90)
at com.sencha.gxt.state.client.StateManager$1.onSuccess(StateManager.java:73)
at com.sencha.gxt.state.client.StateManager$1.onSuccess(StateManager.java:1)
at com.sencha.gxt.state.client.CookieProvider.getValue(CookieProvider.java:54)
at com.sencha.gxt.state.client.StateManager.get(StateManager.java:64)
at com.rfrate.exrate.client.NorthComponent.setComboValue(NorthComponent.java:46)
at com.rfrate.exrate.client.NorthComponent.asWidget(NorthComponent.java:102)
at com.google.gwt.user.client.ui.Widget.asWidgetOrNull(Widget.java:46)
at com.sencha.gxt.widget.core.client.container.Container.add(Container.java:72)
at com.rfrate.exrate.client.ExRate.createNorth(ExRate.java:52) 
at com.rfrate.exrate.client.ExRate.onModuleLoad(ExRate.java:97) ... 9 more

谁能给出一个在cookie中读取和写入变量字符串值的代码示例?

4

1 回答 1

0

我不确定是否使用 StateManager,但要读取写入 cookie,它很简单:

写:

  //javax.servlet.http.Cookie
Cookie localUserId = new Cookie("cookieName", user_info.getLocalDataId());nick_name.setPath("/");
nick_name.setMaxAge(36 * 24 * 60 * 60);
  //appengine specific
this.getThreadLocalResponse().addCookie(localUserId);

读:

    //com.google.gwt.user.client.Cookies;
Cookies.getCookie("cookieName"));
于 2012-10-16T11:26:20.530 回答