Question - How are cookies set in JSP?
Answer -
Setting cookies with JSP involves the following steps:
- Creating a Cookie object: Cookie constructor is called with a cookie name and a cookie value, both are strings.
- Setting the maximum age: setMaxAge is used to specify the length of the cookie(in seconds) should be valid.
- Sending the cookie into the HTTP response headers: response.addCookie is used to add cookies in the HTTP response header.