The name must conform to RFC 2109. That means it can contain only ASCII alphanumeric characters and cannot contain commas, semicolons, or white s " /> 天堂中文av在线资源库,一区二区在线电影,欧美激情一区二区三区蜜桃视频

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

不要在cookie中使用特殊字符的原因分析

Constructs a cookie with a specified name and value.

The name must conform to RFC 2109. That means it can contain only ASCII alphanumeric characters and cannot contain commas, semicolons, or white space or begin with a $ character. The cookie's name cannot be changed after creation.

The value can be anything the server chooses to send. Its value is probably of interest only to the server. The cookie's value can be changed after creation with the setValue method.

By default, cookies are created according to the NETscape cookie specification. The version can be changed with the setVersion method.

以上是Java API文檔中對Cookie類構造函數的說明,重點對name和value可以使用的字符進行了介紹。

參數name需要遵循規范RFC2109,也就是說name參數只能包含字母或者數字,不能包含逗號、分號、空格及美元符號。cookie的name屬性設置之后不能被修改。

參數value可以是服務端設置的任意值,該值可以通過setValue方法進行重新設置。

然后實際情況并非如此!!

(1)value值中不能包含逗號,如果value中包含逗號則程序無法編譯。

如果value中包含逗號,如下:

Cookie pwdCookie = new Cookie("option", "block1,block2");
則異常如下:

Java.lang.IllegalArgumentException: block1,block2
在另外一篇關于JavaScript操作cookie的文章中提到:

在cookie 的名或值中不能使用分號(;)、逗號(,)、等號(=)以及空格。

總之,盡量不要在cookie中使用特殊字符。

JavaScript技術不要在cookie中使用特殊字符的原因分析,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 汉阴县| 普兰店市| 清水县| 固镇县| 衡阳市| 双辽市| 青铜峡市| 宣恩县| 涪陵区| 镇宁| 筠连县| 贵德县| 尖扎县| 得荣县| 平原县| 晋州市| 东丽区| 平安县| 聂荣县| 胶州市| 南部县| 融水| 祁门县| 项城市| 泸水县| 徐州市| 梁河县| 镶黄旗| 高唐县| 平陆县| 安泽县| 三原县| 丘北县| 云阳县| 阳朔县| 霍山县| 贵南县| 蛟河市| 乐至县| 五原县| 普陀区|