码迷,mamicode.com
首页 > 其他好文 > 详细

Servlet中保存的cookie值读取不到

时间:2017-01-24 22:49:28      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:log   let   word   get   设置   使用   set   pat   nbsp   

在设计登录时记住密码功能时,很多时候回使用cookie,在Servlet中保存cookie时,再次访问登录页面,没有读取到保存的cookie值,代码如下:

1 Cookie idCookie = new Cookie("id",String.valueOf(user.getId()));
2  Cookie nameCookie = new Cookie("username",URLEncoder.encode(user.getName(), "utf-8"));
3  Cookie pwdCookie = new Cookie("password",URLEncoder.encode(user.getPwd(), "utf-8"));
4  idCookie.setMaxAge(6000);
5  nameCookie.setMaxAge(6000);
6  pwdCookie.setMaxAge(6000);
7  response.addCookie(idCookie);
8  response.addCookie(nameCookie);
9  response.addCookie(pwdCookie);

如果是在Servlet中保存cookie,一定要设置cookie的路径

  idCookie.setPath("/");  nameCookie.setPath("/");  pwdCookie.setPath("/"); 

 

Servlet中保存的cookie值读取不到

标签:log   let   word   get   设置   使用   set   pat   nbsp   

原文地址:http://www.cnblogs.com/jpwz/p/6347915.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!