java.lang.Object
com.aoapps.servlet.http.Cookies
Helper utility to set, get, remove, encode, and decode cookies.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String comment, int maxAge, boolean secure, boolean contextOnlyPath) Adds a new cookie to the response.static StringdecodeComment(String comment) Gets the comment of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String).static StringdecodeName(String name) Gets the name of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String).static StringdecodePath(String path) Gets the path of a cookie, decoded viaURIDecoder.decodeURI(java.lang.String).static StringdecodeValue(String value) Gets the value of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String).static StringencodeComment(String comment) Encodes the comment of a cookie viaURIEncoder.encodeURIComponent(java.lang.String).static StringencodeName(String name) Encodes the name of a cookie viaURIEncoder.encodeURIComponent(java.lang.String).static StringencodePath(String path) Encodes the path of a cookie viaURIEncoder.encodeURI(java.lang.String).static StringencodeValue(String value) Encodes the value of a cookie viaURIEncoder.encodeURIComponent(java.lang.String).static StringgetComment(Cookie cookie) Gets the comment of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String).static StringgetCookie(HttpServletRequest request, String name) Gets a cookie value given its name ornullif not found.static StringGets the name of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String).static StringGets the path of a cookie, decoded viaURIDecoder.decodeURI(java.lang.String).static StringGets the value of a cookie, decoded viaURIDecoder.decodeURIComponent(java.lang.String).static CookieCreates a new cookie, but does not add it to any response.static CookienewCookie(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 voidremoveCookie(HttpServletRequest request, HttpServletResponse response, String name, boolean secure, boolean contextOnlyPath) Removes a cookie by adding it with maxAge of zero.static StringsetComment(Cookie cookie, String comment) Sets the comment of a cookie, encoded viaURIEncoder.encodeURIComponent(java.lang.String).static StringSets 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 ornullif 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).
-
