request.getCookies()始终为null [英] request.getCookies() is always null

查看:4733
本文介绍了request.getCookies()始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考我之前的问题,我想指出cookie实际上被发送到服务器。
问题是 request.getCookies()总是返回null无论什么。我只能从请求头中像这样检索它们作为字符串

  String cookiesFromHeaderStr = request.getHeader(cookie); 

我不想从头读取它们,因为我必须手动解析字符串。



我使用Javascript设置cookie如下

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

有没有明显的原因为什么cookie不会实际返回请求。 getCookies()

解决方案

b
$ b

建议您创建一个过滤器来设置Cookie。



阅读此讨论从doFilter方法设置Cookie


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()?

解决方案

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

这篇关于request.getCookies()始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆