zoukankan      html  css  js  c++  java
  • 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);
      }

    }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    iOS中Zbar二维码扫描的使用
    SOJ 1135. 飞跃原野
    SOJ 1048.Inverso
    SOJ 1219. 新红黑树
    SOJ 1171. The Game of Efil
    SOJ 1180. Pasting Strings
    1215. 脱离地牢
    1317. Sudoku
    SOJ 1119. Factstone Benchmark
    soj 1099. Packing Passengers
  • 原文地址:https://www.cnblogs.com/cloudLi/p/13208189.html
Copyright © 2011-2022 走看看