Package com.helger.servlet.cookie
Class CookieHelper
- java.lang.Object
-
- com.helger.servlet.cookie.CookieHelper
-
@Immutable public final class CookieHelper extends Object
Misc. helper methods on HTTP cookies.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_AGE_SECONDS
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontainsCookie(jakarta.servlet.http.HttpServletRequest aHttpRequest, String sCookieName)static jakarta.servlet.http.CookiecreateContextCookie(String sName, String sValue, boolean bExpireWhenBrowserIsClosed, boolean bSecure)Create a cookie that is bound to the servlet context path within the local web server.static jakarta.servlet.http.CookiecreateCookie(String sName, String sValue, String sPath, boolean bExpireWhenBrowserIsClosed, boolean bSecure)Create a cookie that is bound on a certain path within the local web server.static com.helger.commons.collection.impl.ICommonsOrderedMap<String,jakarta.servlet.http.Cookie>getAllCookies(jakarta.servlet.http.HttpServletRequest aHttpRequest)static jakarta.servlet.http.CookiegetCookie(jakarta.servlet.http.HttpServletRequest aHttpRequest, String sCookieName)static voidremoveCookie(jakarta.servlet.http.HttpServletResponse aHttpResponse, jakarta.servlet.http.Cookie aCookie)Remove a cookie by setting the max age to 0.
-
-
-
Field Detail
-
DEFAULT_MAX_AGE_SECONDS
public static final int DEFAULT_MAX_AGE_SECONDS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getAllCookies
@Nonnull @ReturnsMutableCopy public static com.helger.commons.collection.impl.ICommonsOrderedMap<String,jakarta.servlet.http.Cookie> getAllCookies(@Nonnull jakarta.servlet.http.HttpServletRequest aHttpRequest)
-
getCookie
@Nullable public static jakarta.servlet.http.Cookie getCookie(@Nonnull jakarta.servlet.http.HttpServletRequest aHttpRequest, @Nonnull String sCookieName)
-
containsCookie
public static boolean containsCookie(@Nonnull jakarta.servlet.http.HttpServletRequest aHttpRequest, @Nonnull String sCookieName)
-
createCookie
@Nonnull public static jakarta.servlet.http.Cookie createCookie(@Nonnull String sName, @Nullable String sValue, String sPath, boolean bExpireWhenBrowserIsClosed, boolean bSecure)
Create a cookie that is bound on a certain path within the local web server.- Parameters:
sName- The cookie name.sValue- The cookie value.sPath- The path the cookie is valid for.bExpireWhenBrowserIsClosed-trueif this is a browser session cookiebSecure-trueto send the cookie from the browser to the server only when using a secure protocol (e.g. https)- Returns:
- The created cookie object.
- Since:
- 9.3.2
-
createContextCookie
@Nonnull public static jakarta.servlet.http.Cookie createContextCookie(@Nonnull String sName, @Nullable String sValue, boolean bExpireWhenBrowserIsClosed, boolean bSecure)
Create a cookie that is bound to the servlet context path within the local web server.- Parameters:
sName- The cookie name.sValue- The cookie value.bExpireWhenBrowserIsClosed-trueif this is a browser session cookiebSecure-trueto send the cookie from the browser to the server only when using a secure protocol (e.g. https)- Returns:
- The created cookie object.
- Since:
- 9.3.2
-
removeCookie
public static void removeCookie(@Nonnull jakarta.servlet.http.HttpServletResponse aHttpResponse, @Nonnull jakarta.servlet.http.Cookie aCookie)
Remove a cookie by setting the max age to 0.- Parameters:
aHttpResponse- The HTTP response. May not benull.aCookie- The cookie to be removed. May not benull.
-
-