zoukankan      html  css  js  c++  java
  • cookie在后台的存取

    /************存***********/
    //获取cookie值
    String cookieValue = "";
    Cookie[] cookies = request.getCookies();
    if (cookies != null) { //防止出现nullpoint错误
    for (Cookie cookie : cookies) {
    if (cookie.getName().equals("myCookie")) {
    cookieValue = cookie.getValue();
    }
    }
    }
    //更新cookie的值(id为新的存储到cookie里面的值)
    cookieValue = cookieValue + id.toString() + "%";
    Cookie userCookie = new Cookie("myCookie", cookieValue);
    userCookie.setMaxAge(30 * 24 * 60 * 60); //存活期为一个月 30*24*60*60
    userCookie.setPath("/");
    response.addCookie(userCookie);
    /************存***********/

    /************取***********/
    //再次获取cookie的值
    //此处已经获取到存在cookie中的id值,现拆分并从数据库中查询对应对象的集合
    String[] cookId = cookieValue.substring(0, cookieValue.length() - 1).split("%");
    /************取***********/

    controller参数里面需要HttpServletResponse response、HttpServletRequest request

    response存,request取

  • 相关阅读:
    libusbwin32
    KMP
    windows.h
    iomanip
    C++继承
    LIST
    fstream
    VS2010中调试c++程序的方法
    sstream
    char 与char* 字符串与字符
  • 原文地址:https://www.cnblogs.com/zhangyong0908/p/9339979.html
Copyright © 2011-2022 走看看