The HttpServletResponse addCookie method is used to add a cookie to the HTTP response object. This method takes a Cookie object as a parameter and adds it to the response.
Example 1:
Cookie cookie = new Cookie("name", "value"); response.addCookie(cookie);
This example creates a new cookie with the name "name" and value "value", and adds it to the HTTP response.
Example 2:
Cookie cookie = new Cookie("name", "value"); cookie.setMaxAge(3600); response.addCookie(cookie);
This example sets the maximum age of the cookie to 3600 seconds (1 hour) and adds it to the HTTP response.
Example 3:
Cookie cookie = new Cookie("name", "value"); cookie.setSecure(true); response.addCookie(cookie);
This example sets the cookie as secure, meaning that it can only be transmitted over a secure HTTPS connection, and adds it to the HTTP response.
The package library for javax.servlet.http is the Java Servlet API.
Java HttpServletResponse.addCookie - 30 examples found. These are the top rated real world Java examples of javax.servlet.http.HttpServletResponse.addCookie extracted from open source projects. You can rate examples to help us improve the quality of examples.