code: public static void setCookie(HttpServletResponse response, String name,
                                   String value, String domain, int maxAge) {
          if (value == null) {
              value = "";
          }
          Cookie cookie = new Cookie(name, value);
          cookie.setMaxAge(maxAge);
          if (domain != null && !"".equals(domain)) {
              cookie.setDomain(domain);
          }
          cookie.setPath("/");
          response.addCookie(cookie);
      }
docs: https://code.google.com/p/util-java/source/browse/trunk/src/utils/
  CookieUtils.java?r=6
  
  @param response
  @param name
  @param value
  @param domain
  @param maxAge