• java--cookie


    package com.test;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**

    • Servlet implementation class cookie
      */
      public class cookie extends HttpServlet {

      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      Cookie[] cookies=request.getCookies();
      if(cookies != null) {
      for (Cookie cookie : cookies) {
      System.out.println(cookie.getName()+"---"+cookie.getValue());
      }
      }
      Cookie cookie = new Cookie("name","zhangsan");
      response.addCookie(cookie);
      Cookie cookie2 = new Cookie("age","18");
      response.addCookie(cookie2);
      //设置cookie有效期,参数以秒计算
      cookie.setMaxAge(600);

       response.getWriter().write(cookie.getName()+"---"+cookie.getValue()+"---"+cookie2.getName()+"---"+cookie2.getValue());
      

      }

      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      doGet(request, response);
      }

    }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    scala :: , +:, :+ , ::: , ++ 的区别
    Scala 函数式编程思想
    Scala 关键字
    HDFS 的内存存储是什么?
    LRU
    高并发情况限流
    Java中List集合去除重复数据的方法
    MySQL支持的跨库事务
    死磕ConcurrentHashMap 1.8源码解析
    一致性Hash算法
  • 原文地址:https://www.cnblogs.com/cloudLi/p/13208189.html
Copyright © 2020-2023  润新知