javax.servlet.http.Cookie.clone()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中javax.servlet.http.Cookie.clone()方法的一些代码示例,展示了Cookie.clone()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.clone()方法的具体详情如下:
包路径:javax.servlet.http.Cookie
类名称:Cookie
方法名:clone

Cookie.clone介绍

[英]Overrides the standard java.lang.Object.clone method to return a copy of this Cookie.
[中]重写标准java.lang.Object.clone方法以返回此Cookie的副本。

代码示例

代码示例来源:origin: com.sun.grizzly/grizzly-http-servlet

/**
 *
 * Overrides the standard <code>java.lang.Object.clone</code> 
 * method to return a copy of this cookie.
 *        
 *
 */
@Override
public Object clone() {
  return wrappedCookie.clone();
}

代码示例来源:origin: org.apache.wicket/wicket-core

/**
 * Make a copy of the passed cookie.
 * 
 * @param cookie
 *            The cookie to copy
 * @return A copy of the passed cookie. May be {@code null} if the argument is {@code null}.
 */
public static Cookie copyOf(Cookie cookie)
{
  return cookie != null ? (Cookie) cookie.clone() : null;
}

代码示例来源:origin: apache/wicket

/**
 * Make a copy of the passed cookie.
 * 
 * @param cookie
 *            The cookie to copy
 * @return A copy of the passed cookie. May be {@code null} if the argument is {@code null}.
 */
public static Cookie copyOf(Cookie cookie)
{
  return cookie != null ? (Cookie) cookie.clone() : null;
}

代码示例来源:origin: com.semanticcms/semanticcms-core-servlet

private static Cookie[] copyCookies(Cookie[] cookies) {
  if(cookies == null) return null;
  Cookie[] copy = new Cookie[cookies.length];
  for(int i=0; i<cookies.length; i++) {
    copy[i] = (Cookie)cookies[i].clone();
  }
  return copy;
}

代码示例来源:origin: javaee/grizzly

@SuppressWarnings("UnusedDeclaration")
public Object cloneCookie() {
  return wrappedCookie.clone();
}

代码示例来源:origin: javaee/grizzly

@SuppressWarnings("UnusedDeclaration")
public Object cloneCookie() {
  return wrappedCookie.clone();
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server

@SuppressWarnings("UnusedDeclaration")
public Object cloneCookie() {
  return wrappedCookie.clone();
}

代码示例来源:origin: javaee/grizzly

@SuppressWarnings("UnusedDeclaration")
public Object cloneCookie() {
  return wrappedCookie.clone();
}

代码示例来源:origin: javaee/grizzly

@SuppressWarnings("UnusedDeclaration")
public Object cloneCookie() {
  return wrappedCookie.clone();
}

代码示例来源:origin: javaee/grizzly

@SuppressWarnings("UnusedDeclaration")
public Object cloneCookie() {
  return wrappedCookie.clone();
}

代码示例来源:origin: org.glassfish.soteria/javax.security.enterprise

private static Cookie[] copyCookies(Cookie[] cookies) {
  
  if (isEmpty(cookies)) {
    return cookies;
  }
  
  ArrayList<Cookie> copiedCookies = new ArrayList<>();
  for (Cookie cookie : cookies) {
    copiedCookies.add((Cookie)cookie.clone());
  }
  
  return copiedCookies.toArray(new Cookie[copiedCookies.size()]);
}

代码示例来源:origin: javaee/security-soteria

private static Cookie[] copyCookies(Cookie[] cookies) {
  
  if (isEmpty(cookies)) {
    return cookies;
  }
  
  ArrayList<Cookie> copiedCookies = new ArrayList<>();
  for (Cookie cookie : cookies) {
    copiedCookies.add((Cookie)cookie.clone());
  }
  
  return copiedCookies.toArray(new Cookie[copiedCookies.size()]);
}

代码示例来源:origin: stackoverflow.com

public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
  //This search may or may not actually be necessary, you might be able to just
  // create a new cookie with the right name
  for(Cookie cookie : request.getCookies()) {
    if(cookie.getName() == "JSESSIONID") {
      //Clear one cookie
      cookie.setName("");
      cookie.setMaxAge(0);
      cookie.setPath(request.getContextPath());
      response.addCookie(cookie);
      //Clear the other cookie
      Cookie cookieWithSlash = cookie.clone();
      cookieWithSlash.setPath(request.getContextPath() + "/");
      response.addCookie(cookieWithSlash);
    }
  }
  //This is actually a filter; continue along the chain
  super.onLogoutSuccess(request, response, authentication);
}

代码示例来源:origin: juzu/juzu

public void addCookie(Cookie cookie) {
 cookies.add((Cookie)cookie.clone());
}

代码示例来源:origin: org.juzu/juzu-core

public void addCookie(Cookie cookie) {
 cookies.add((Cookie)cookie.clone());
}

代码示例来源:origin: org.juzu/juzu-core

public Cookie[] getCookies() {
 Cookie[] c = new Cookie[cookies.size()];
 for (int i = 0;i < cookies.size();i++) {
  c[i] = (Cookie)cookies.get(i).clone();
 }
 return c;
}

代码示例来源:origin: juzu/juzu

public Cookie[] getCookies() {
 Cookie[] c = new Cookie[cookies.size()];
 for (int i = 0;i < cookies.size();i++) {
  c[i] = (Cookie)cookies.get(i).clone();
 }
 return c;
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

/**
 * Internal method used for dropping cookies
 *
 * @param response
 * @param cookies
 * @param cookiePath
 * @return
 */
private static int dropCookies(final HttpServletResponse response, final Cookie[] cookies, final String cookiePath) {
  int count = 0;
  for (final Cookie cookie : cookies) {
    if (cookie == null) {
      continue;
    }
    final Cookie responseCookie = (Cookie) cookie.clone();
    responseCookie.setMaxAge(0);
    responseCookie.setPath(cookiePath);
    responseCookie.setValue("");
    addCookie(responseCookie, response);
    count++;
  }
  return count;
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

/**
 * <p>
 * Extend the cookie life.
 * <p></p>
 * This can be used when a cookie should be valid for X minutes from the last point of activity.
 * <p></p>
 * This method will leave expired or deleted cookies alone.
 * </p>
 *
 * @param request    Request to get the Cookie from
 * @param response   Response to write the extended Cookie to
 * @param cookieName Name of Cookie to extend the life of
 * @param expiry     New Cookie expiry
 */
public static boolean extendCookieLife(final HttpServletRequest request, final HttpServletResponse response,
                    final String cookieName, final String cookiePath, final int expiry) {
  final Cookie cookie = getCookie(request, cookieName);
  if (cookie == null) {
    return false;
  }
  if (cookie.getMaxAge() <= 0) {
    return false;
  }
  final Cookie responseCookie = (Cookie) cookie.clone();
  responseCookie.setMaxAge(expiry);
  responseCookie.setPath(cookiePath);
  addCookie(responseCookie, response);
  return true;
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

/**
   * Internal method used for dropping cookies
   *
   * @param response
   * @param cookies
   * @param cookiePath
   * @return
   */
  private static int dropCookies(final HttpServletResponse response, final Cookie[] cookies, final String cookiePath) {
    int count = 0;

    for (final Cookie cookie : cookies) {
      if (cookie == null) {
        continue;
      }

      final Cookie responseCookie = (Cookie) cookie.clone();
      responseCookie.setMaxAge(0);
      responseCookie.setPath(cookiePath);
      responseCookie.setValue("");

      addCookie(responseCookie, response);
      count++;
    }

    return count;
  }
}

相关文章