作者sudada (叽咕叽咕叽咕)
看板java
标题[J2EE] servlet的cookie问题
时间Wed Dec 31 20:17:13 2008
请问
cookie的字串是不是不能包含空格?
因为我想把日期写到cookie里面 但是一直失败
後来发现字串里面有空格
在temoporary internetfiles里面就会找不到
但是api里面没有写到这个
好像只有写到name的限制
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.
以下是程式码
final int AGE = 180000;
Date date = new Date();
Cookie Visiteddate = new Cookie("Visiteddate",date.toString());
Visiteddate.setMaxAge(AGE);
response.addCookie(Visiteddate);
这样写法会写不进去...
但是只要把date里面的月份日期抓出来
只要不包含空格就可以存了
只是这样很麻烦...
请问cookie有这样的限制吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.161.208.233
1F:推 SHANGOYANYI:有 存到cookie的字串不能有空格 01/01 12:30