java.lang.Object
com.aoapps.servlet.http.Cookies
Helper utility to set, get, remove, encode, and decode cookies.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addCookie
(HttpServletRequest request, HttpServletResponse response, String name, String value, String comment, int maxAge, boolean secure, boolean contextOnlyPath) Adds a new cookie to the response.static String
decodeComment
(String comment) Gets the comment of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.static String
decodeName
(String name) Gets the name of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.static String
decodePath
(String path) Gets the path of a cookie, decoded viaURIDecoder.decodeURI(java.lang.String)
.static String
decodeValue
(String value) Gets the value of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.static String
encodeComment
(String comment) Encodes the comment of a cookie viaURIEncoder.encodeURIComponent(java.lang.String)
.static String
encodeName
(String name) Encodes the name of a cookie viaURIEncoder.encodeURIComponent(java.lang.String)
.static String
encodePath
(String path) Encodes the path of a cookie viaURIEncoder.encodeURI(java.lang.String)
.static String
encodeValue
(String value) Encodes the value of a cookie viaURIEncoder.encodeURIComponent(java.lang.String)
.static String
getComment
(Cookie cookie) Gets the comment of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.static String
getCookie
(HttpServletRequest request, String name) Gets a cookie value given its name ornull
if not found.static String
Gets the name of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.static String
Gets the path of a cookie, decoded viaURIDecoder.decodeURI(java.lang.String)
.static String
Gets the value of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.static Cookie
Creates a new cookie, but does not add it to any response.static Cookie
newCookie
(HttpServletRequest request, String name, String value, String comment, int maxAge, boolean secure, boolean contextOnlyPath) Creates a new cookie, but does not add it to any response.static void
removeCookie
(HttpServletRequest request, HttpServletResponse response, String name, boolean secure, boolean contextOnlyPath) Removes a cookie by adding it with maxAge of zero.static String
setComment
(Cookie cookie, String comment) Sets the comment of a cookie, encoded viaURIEncoder.encodeURIComponent(java.lang.String)
.static String
Sets the path of a cookie, encoded viaURIEncoder.encodeURI(java.lang.String)
.
-
Method Details
-
encodeName
Encodes the name of a cookie viaURIEncoder.encodeURIComponent(java.lang.String)
.- Returns:
- The encoded name
- See Also:
-
encodeValue
Encodes the value of a cookie viaURIEncoder.encodeURIComponent(java.lang.String)
.- Returns:
- The encoded value
- See Also:
-
encodeComment
Encodes the comment of a cookie viaURIEncoder.encodeURIComponent(java.lang.String)
.- Returns:
- The encoded comment
- See Also:
-
encodePath
Encodes the path of a cookie viaURIEncoder.encodeURI(java.lang.String)
.- Returns:
- The encoded path
- See Also:
-
decodeName
Gets the name of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.- Returns:
- The decoded name
- See Also:
-
decodeValue
Gets the value of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.- Returns:
- The decoded value
- See Also:
-
decodeComment
Gets the comment of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.- Returns:
- The decoded comment
- See Also:
-
decodePath
Gets the path of a cookie, decoded viaURIDecoder.decodeURI(java.lang.String)
.- Returns:
- The decoded path
- See Also:
-
newCookie
Creates a new cookie, but does not add it to any response. Encodes name and value viaURIEncoder.encodeURIComponent(java.lang.String)
.- Returns:
- The new cookie
- See Also:
-
setComment
Sets the comment of a cookie, encoded viaURIEncoder.encodeURIComponent(java.lang.String)
.- Returns:
- The encoded comment
- See Also:
-
setPath
Sets the path of a cookie, encoded viaURIEncoder.encodeURI(java.lang.String)
.- Returns:
- The encoded path
- See Also:
-
getName
Gets the name of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.- Returns:
- The decoded name
- See Also:
-
getValue
Gets the value of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.- Returns:
- The decoded value
- See Also:
-
getComment
Gets the comment of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String)
.- Returns:
- The decoded comment
- See Also:
-
getPath
Gets the path of a cookie, decoded viaURIDecoder.decodeURI(java.lang.String)
.- Returns:
- The decoded path
- See Also:
-
newCookie
public static Cookie newCookie(HttpServletRequest request, String name, String value, String comment, int maxAge, boolean secure, boolean contextOnlyPath) Creates a new cookie, but does not add it to any response. Encodes name, value, and comment viaURIEncoder.encodeURIComponent(java.lang.String)
. Encodes path viaURIEncoder.encodeURI(java.lang.String)
. -
addCookie
public static void addCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String comment, int maxAge, boolean secure, boolean contextOnlyPath) Adds a new cookie to the response. Encodes name, value, and comment viaURIEncoder.encodeURIComponent(java.lang.String)
. Encodes path viaURIEncoder.encodeURI(java.lang.String)
. -
getCookie
Gets a cookie value given its name ornull
if not found. Encodes name and value viaURIEncoder.encodeURIComponent(java.lang.String)
. -
removeCookie
public static void removeCookie(HttpServletRequest request, HttpServletResponse response, String name, boolean secure, boolean contextOnlyPath) Removes a cookie by adding it with maxAge of zero. Encodes name viaURIEncoder.encodeURIComponent(java.lang.String)
.
-