code: public static Cookie getCookie(HttpServletRequest request, String name) {
      Cookie[] cookies = request.getCookies();
      Cookie returnCookie = null;
  
      if (cookies == null) { return returnCookie; }
      for (int i = 0; i < cookies.length; i++) {
        Cookie thisCookie = cookies[i];
        if (thisCookie.getName().equals(name) && !thisCookie.getValue().equals("")) {
          returnCookie = thisCookie;
          break;
        }
      }
      return returnCookie;
    }
docs: Convenience method to get a cookie by name
  
  @param request
  the current request
  @param name
  the name of the cookie to find
  @return the cookie (if found), null if not found