cookies

 
cookies 存储中文:
向客户端响应中添加Cookie

          String name = URLEncoder.encode("姓名", "UTF-8");
          String value = URLEncoder.encode("张三", "UTF-8");
          Cookie c = new Cookie(name, value);
          c.setMaxAge(3600);
          response.addCookie(c);
   
  
从客户端请求中获取Cookie

          response.setContentType("text/html;charset=utf-8");
          Cookie[] cs = request.getCookies();
          if(cs != null) {
              for(Cookie c : cs) {
                 String name = URLDecoder.decode(c.getName(), "UTF-8");
                 String value = URLDecoder.decode(c.getValue(), "UTF-8");
                  String s = name + ": " + value + "<br/>";
                 response.getWriter().print(s);
              }
          }
   
  
---------------------
作者:李昆鹏
来源:CSDN
原文:https://blog.csdn.net/weixin_41547486/article/details/81294250
版权声明:本文为博主原创文章,转载请附上博文链接!
posted @ 2019-05-05 22:50  笔记Next  阅读(282)  评论(0编辑  收藏  举报