在Java中设置cookie的方法有以下几种:
Cookie cookie = new Cookie("cookieName", "cookieValue");
response.addCookie(cookie);
Cookie cookie = new Cookie("cookieName", "cookieValue");
cookie.setMaxAge(60 * 60); // 设置cookie的有效期为1小时
response.addCookie(cookie);
Cookie cookie = new Cookie("cookieName", "cookieValue");
cookie.setPath("/path"); // 设置cookie的路径
cookie.setDomain("example.com"); // 设置cookie的域
response.addCookie(cookie);
Cookie cookie = new Cookie("cookieName", "cookieValue");
cookie.setSecure(true); // 设置cookie为安全cookie
response.addCookie(cookie);
Cookie cookie = new Cookie("cookieName", "cookieValue");
cookie.setHttpOnly(true); // 设置cookie为HttpOnly cookie
response.addCookie(cookie);