code: public static void addCookie(HttpServletRequest request, HttpServletResponse response,
              String name, String value, String domain, String contextPath, int maxAge,boolean httpOnly) {
          if (request != null && response != null) {
              Cookie cookie = new Cookie(name, value);
              cookie.setMaxAge(maxAge);
              cookie.setSecure(request.isSecure());
  
              if (contextPath == null || contextPath.isEmpty()) {
                  cookie.setPath("/");
              } else {
                  cookie.setPath(contextPath);
              }
  
              if (domain != null && !domain.isEmpty()) {
                  cookie.setDomain(domain);
              }
  
              if(httpOnly){
                  cookie.setHttpOnly(true);
              }
  
              response.addCookie(cookie);
              log.debug("Cookie update the sessionID.[name={},value={},maxAge={},httpOnly={},path={},domain={}]",
                      cookie.getName(),cookie.getValue(), cookie.getMaxAge(),httpOnly,cookie.getPath(),
                      cookie.getDomain());
          }
      }
docs: add a cookie