public final class Cookies extends Object
HttpServletRequest
s and
HttpServletResponse
s.Modifier and Type | Method and Description |
---|---|
static Map.Entry<String,String> |
createCookieHeader(Collection<String> cookies)
Create a semicolon-delimited cookie header for the specified
cookies . |
static String |
getCookieValue(HttpServletRequest request,
String name)
Returns the cookie value associated with the given cookie name from the
given
request . |
static void |
removeCookie(HttpServletResponse response,
String name)
Remove the cookie in the
response with the provided name . |
static void |
setCookieValue(HttpServletResponse response,
String name,
String value,
int maxAge)
Set the cookie in the
response with the provided name ,
value , and expiration maxAge . |
public static String getCookieValue(HttpServletRequest request, String name)
request
.request
- The request.name
- The cookie name.null
if the cookie name
is not found in the
request
.NullPointerException
- If request
or name
is null.public static void setCookieValue(HttpServletResponse response, String name, String value, int maxAge)
response
with the provided name
,
value
, and expiration maxAge
.response
- The HttpServletResponse to be used.name
- The cookie name to associate the cookie value with.value
- The actual cookie value to be set in the given servlet
response.maxAge
- The expiration interval in seconds. If this is set to 0, then
the cookie will immediately expire.NullPointerException
- If response
is null.IllegalArgumentException
- If the cookie name is null or empty or
contains any illegal characters (for example, a comma, space, or
semicolon) or matches a token reserved for use by the cookie
protocol.public static void removeCookie(HttpServletResponse response, String name)
response
with the provided name
.
The cookie expiration interval is set to zero, resulting in the cookie being expired immediately.
response
- The HttpServletResponse to be used.name
- The cookie name of the cookie to be removed.NullPointerException
- If response
is null.IllegalArgumentException
- If the cookie name is null or empty or
contains any illegal characters (for example, a comma, space, or
semicolon) or matches a token reserved for use by the cookie
protocol.public static Map.Entry<String,String> createCookieHeader(Collection<String> cookies)
cookies
.cookies
- The collection of cookies.Map.Entry<String,String>
with key set to
"Cookie"
, and value set to semicolon-delimited
cookies
.NullPointerException
- If cookies
is null.Copyright © 2020 LibJ. All rights reserved.