不能从Java中的cookie获取值。值包含逗号。 [英] Cannot get value from cookie in Java. Value contains commas.

查看:1577
本文介绍了不能从Java中的cookie获取值。值包含逗号。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从包含逗号的cookie获得值的问题。它返回不是完整的字符串,但字符串截断到第一个逗号。例如:

I have problem with getting value from cookie that contains commas. It returns not full string but string cut off to first comma. For example:

// cookie value = var1,var2,var3
String cookieVal = cookie.getValue();
//cookieVal now is "var1" instead of "var1,var2,var3"

// cookie value = var1=var2=var3
String cookieVal = cookie.getValue();
//cookieVal now is "var1=var2=var3"

推荐答案

查看 Cookie文档。它说:


此类支持版本0
(由Netscape)和版本1(由RFC
2109)cookie规范。默认情况下,
是使用
版本0创建的,以确保最佳的
互操作性。

This class supports both the Version 0 (by Netscape) and Version 1 (by RFC 2109) cookie specifications. By default, cookies are created using Version 0 to ensure the best interoperability.

如果您看到 setValue 方法你会发现这

And if you see the setValue method you will find this


对于版本0的cookies,值不应该包含空格, ,括号,等号,逗号,双引号,斜杠,问号,符号,冒号和分号。空值在所有浏览器上的行为可能不一样。

With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons. Empty values may not behave the same way on all browsers.

编辑:只读google的东西。也许尝试将版本设置为1,看看它是如何工作。

Just read the google thing. Maybe try setting the version to 1 and see how it works.

这篇关于不能从Java中的cookie获取值。值包含逗号。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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