开发者

GWT Cookies, returning null when setting during an rpc

开发者 https://www.devze.com 2023-02-02 13:05 出处:网络
I am becoming almost mad with the GWT Cookies, in one of my application I set the cookie in an RPC success, but I am trying to retrieve it in another place of my application, it returns null.

I am becoming almost mad with the GWT Cookies,

in one of my application I set the cookie in an RPC success, but I am trying to retrieve it in another place of my application, it returns null.

I know that when setting a variable in an rpc sucess,if we try to access it elsewhere it result null, so how can i set a cookie an rpc so that it does not returns null??

Edit:- I am doing something like this:

I do in Main.java

RPC.getUserDetails(new 开发者_如何学运维AsyncCallback <String>())
{
  public void onSuccess(String result)
  {
      Cookies.set("UserDetails",result);
  }
}

Now in another file.java, when i do Cookies.get("UserDetails"), I get null


I had the same problem and after setting expiration time I was able to retrieve it:

Date now = new Date();
long week = now.getTime();
week = week + (1000 * 60 * 60 * 24 * 7);
Cookies.setCookie("UserDetails", result, week);

Also make sure that you are setting none secure cookie and are retrieving none secure cookie. Make sure by checking the browser if the cookie file exists. And check the content of the file. If you have problems after this post the content of the cookie file here.


I tried it also this way:

Date expires = new Date(System.currentTimeMillis() + (1000 * 3600 * 24));
String categoriesCookieJson = asJson(allCategories);
System.out.println("inserting cat cookie lenth : " + categoriesCookieJson.toCharArray().length + " : " + categoriesCookieJson);
Cookies.setCookie(VU_ME_CATEGORIES_CACHE, categoriesCookieJson, expires);

String categoriesJsonCookieCache = Cookies.getCookie(VU_ME_CATEGORIES_CACHE);
System.out.println("cookie in chache " + categoriesJsonCookieCache);

it returns null and there's no cookie file entry (looking in ff firebug)

inserting cat cookie lenth : 8303 : {"categories":[{"id":"71","name":"Immoblier","children":[{"id":"76","parentKey":"71","name":"Terrain....

cookie in chache null

Ok!!! so it seams it's related to the size of my cookie content:

inserting cat cookie length : 8303 

I will have to split the data

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号