request.getCookies() is always null

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

With reference my previous question I would like to indicate that the cookies are actually getting sent to the server. Problem is that request.getCookies() always return null no matter what. I can only retrieve them as a String from the request header like this

String cookiesFromHeaderStr = request.getHeader("cookie"); 

I don't want to read them from the header because I will have to parse the string manually.

I am setting the cookie using Javascript as follows

document.cookie = "loc={\"lng\":0.111111,\"lat\":50.111111}, expires=Wed, 05 Oct 2016 16:22:11 GMT, path=/\"" 

Is there an obvious reason why the cookies won't actually be returned with request.getCookies()?

回答1:

It's not secure to set cookies from javascript.

I suggest you to create a filter which will set the cookies.

Read this discussion Setting cookie from doFilter method



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!