zoukankan      html  css  js  c++  java
  • Servlet中保存的cookie值读取不到

    在设计登录时记住密码功能时,很多时候回使用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("/"); 

  • 相关阅读:
    jQuery(四)
    jQuery(三)
    jQuery(二)
    jQuery(一)
    JS(四)
    JS(三)
    JS(二)
    类似openDialog的弹窗
    vue的异步组件按需加载
    vue实现点击、滑动右侧字母对应各个城市
  • 原文地址:https://www.cnblogs.com/jpwz/p/6347915.html
Copyright © 2011-2022 走看看