读书人

如何在服务器端设置cookies使其不写入

发布时间: 2013-03-06 16:20:31 作者: rapoo

怎么在服务器端设置cookies使其不写入本地
大家好:用cookies的什么方法设置cookies的属性,使其不能从服务器写入客户端文件中,只能随网页存在而存在。
Cookie cookie = new Cookie("Session-Cookie" + i, "Session-Value-S" + i);
response.addCookie(cookie);
服务器往浏览器写的cookies,怎样写才能只写入内存中,不写入本地文本中。然后浏览器一关闭,那个暂时的cookies也就没了。求助。非常非常感谢,求几句代码+文字说明
[解决办法]
不设置存活时间就行了
[解决办法]
浏览器写不写文件这个真的很难保证。默认的cookie就是会话级,也就是一致有效直到浏览器关闭。
参考:RFC6265§5.3.3
你设置max-age为0,反而有可能导致生成文件。

引用
3. If the cookie-attribute-list contains an attribute with an
attribute-name of "Max-Age":

Set the cookie's persistent-flag to true.

Set the cookie's expiry-time to attribute-value of the last
attribute in the cookie-attribute-list with an attribute-name
of "Max-Age".

读书人网 >Java Web开发

热点推荐