!--a11y-->
Setting Cookies in HTTP Servlets 
To be able to set a cookie to the HTTP response object, you must first create it. You do this using the Cookieconstructor that takes the cookie name and cookie value as parameters.

This example creates a cookie called MyFirstCookie with value of 1.
|
Cookie SapCookie = new Cookie("MyFirstCookie", "1"); |
You add the cookie to the browser using the addCookie(Cookie cookie) method of the HttpServletResponse object. Before you add the cookie, you can set various attributes to it, such as comments, the maximum time that the cookie can live before it expires, and so on.
For more information about the methods that you can use to set attributes to a cookie, see the Cookie class methods of Java Servlet 2.3 API.

|
SapCookie.setMaxAge(Integer.MAX_VALUE); SapCookie.setComment( "Just an example" ); //Add the cookie to the response response.addCookie(SapCookie); |
The Set-Cookie header is set to your HTTP response headers.
