在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);