@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8"); PrintWriter out = resp.getWriter(); Cookie cookie=new Cookie("my", "my name is lsh"); cookie.setDomain(".demo.com"); //设置 demo.com所有的子域名都有效
cookie.setPath("/"); //设置路径
cookie.setMaxAge(60*60*24); //设置有效时间 以秒为单位 resp.addCookie(cookie); //设置到请求头当中 out.println("设置cookie成功"); }