문제

I had a GWT servelt on whose doGet method, I created a cookie as shown below:

Cookie nameCookie = new Cookie("name","adam");
response.addCookie(nameCookie);

I tried to read this on the client side as

String name = Cookies.getCookie("name");

But the output of string variable name was coming out as undefined.

도움이 되었습니까?

해결책

I solved it by finding out that while creating a cookie, you also have to set the path for it. So in the server side,

Cookie nameCookie = new Cookie("name","adam");
nameCookie.setPath("/");
response.addCookie(nameCookie);

Now the following client side code returns the proper value as adam

String name = Cookies.getCookie("name");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top