栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

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

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

不要在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中使用特殊字符。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/115674.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号