Class CookieUtils

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CookieUtils.Lifespan
      Some cookie lifespan to play with.
    • Constructor Summary

      Constructors 
      Constructor Description
      CookieUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getParameterValue​(javax.servlet.http.HttpServletRequest request, java.lang.String name)
      Returns the value of a request parameter, or if not found tries to find a cookie with the same name.
      static void setCookie​(javax.servlet.http.HttpServletResponse response, java.lang.String name, java.lang.String value)
      Set a cookie on the client, with a default lifespan of @see Lifespan#HOUR
      static void setCookie​(javax.servlet.http.HttpServletResponse response, java.lang.String name, java.lang.String value, CookieUtils.Lifespan lifeSpan)
      Set a cookie on the client.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getParameterValue

        public static final java.lang.String getParameterValue​(javax.servlet.http.HttpServletRequest request,
                                                               java.lang.String name)
        Returns the value of a request parameter, or if not found tries to find a cookie with the same name.
        Parameters:
        request - the HTTP request
        name - the parameter name
        Returns:
        the value (never null, may be empty)
      • setCookie

        public static final void setCookie​(javax.servlet.http.HttpServletResponse response,
                                           java.lang.String name,
                                           java.lang.String value,
                                           CookieUtils.Lifespan lifeSpan)
        Set a cookie on the client.
        Parameters:
        response - the HTTP response wrapper
        name - the cookie name
        value - the cookie value
        lifeSpan - the cookie TTL as an CookieUtils.Lifespan enum value
      • setCookie

        public static final void setCookie​(javax.servlet.http.HttpServletResponse response,
                                           java.lang.String name,
                                           java.lang.String value)
        Set a cookie on the client, with a default lifespan of @see Lifespan#HOUR
        Parameters:
        response - the HTTP response wrapper
        name - the cookie name
        value - the cookie value