Demo03 :
package com.test.cookie;
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 Demo03
* 设置cookie有效期及cookie常用方法
*/
public class Demo03 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.发送客户端 可以给客户端返回多个cookie
Cookie cookie = new Cookie("name", "lisi");
response.addCookie(cookie);
Cookie cookie1 = new Cookie("sex", "men");
response.addCookie(cookie1);
//2.获取带客户端的数据
Cookie[] cookies = request.getCookies();
if(cookies !