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

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

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

Cookie.setComment介绍

[英]Specifies a comment that describes a cookie's purpose. The comment is useful if the browser presents the cookie to the user. Comments are not supported by Netscape Version 0 cookies.
[中]指定描述cookie用途的注释。如果浏览器向用户呈现cookie,则注释很有用。Netscape版本0 Cookie不支持注释。

代码示例

代码示例来源:origin: ninjaframework/ninja

public static Cookie convertNinjaCookieToServletCookie(ninja.Cookie cookie) {
  Cookie servletCookie = new Cookie(cookie.getName(), cookie.getValue());
  servletCookie.setMaxAge(cookie.getMaxAge());
  if (cookie.getComment() != null) {
    servletCookie.setComment(cookie.getComment());
  }
  if (cookie.getDomain() != null) {
    servletCookie.setDomain(cookie.getDomain());
  }
  if (cookie.isSecure()) {
    servletCookie.setSecure(true);
  }
  if (cookie.getPath() != null) {
    servletCookie.setPath(cookie.getPath());
  }
  if (cookie.isHttpOnly()) {
    SERVLET_COOKIE_FALLBACK_HANDLER.setHttpOnly(servletCookie);
  }
  return servletCookie;
}

代码示例来源:origin: spring-projects/spring-framework

public void printResponse() throws Exception {
  Cookie enigmaCookie = new Cookie("enigma", "42");
  enigmaCookie.setComment("This is a comment");
  enigmaCookie.setHttpOnly(true);
  enigmaCookie.setMaxAge(1234);

代码示例来源:origin: rest-assured/rest-assured

javax.servlet.http.Cookie servletCookie = new javax.servlet.http.Cookie(cookie.getName(), cookie.getValue());
if (cookie.hasComment()) {
  servletCookie.setComment(cookie.getComment());

代码示例来源:origin: com.google.inject.extensions/guice-servlet

public ImmutableCookie(Cookie original) {
 super(original.getName(), original.getValue());
 super.setMaxAge(original.getMaxAge());
 super.setPath(original.getPath());
 super.setComment(original.getComment());
 super.setSecure(original.getSecure());
 super.setValue(original.getValue());
 super.setVersion(original.getVersion());
 if (original.getDomain() != null) {
  super.setDomain(original.getDomain());
 }
}

代码示例来源:origin: Netflix/hollow

public static HollowUISession getSession(HttpServletRequest req, HttpServletResponse resp) {
  Long sessionId = null;
  if(req.getCookies() != null) {
    for(Cookie cookie : req.getCookies()) {
      if("hollowDiffSessionId".equals(cookie.getName())) {
        sessionId = Long.valueOf(cookie.getValue());
      }
    }
  }
  if(sessionId == null) {
    sessionId = new Random().nextLong() & Long.MAX_VALUE;
    Cookie cookie = new Cookie("hollowDiffSessionId", sessionId.toString());
    cookie.setComment(Response.HTTP_ONLY_COMMENT);
    resp.addCookie(cookie);
  }
  HollowUISession session = sessions.get(sessionId);
  if(session == null) {
    session = new HollowUISession();
    HollowUISession existingSession = sessions.putIfAbsent(sessionId, session);
    if(existingSession != null)
      session = existingSession;
  }
  return session;
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

public static Cookie deserialize(byte[] bytes) {
  Deserializer deserializer = new Deserializer(ByteBuffer.wrap(bytes));
  String comment = deserializer.readString();
  String domain = deserializer.readString();
  boolean httpOnly = deserializer.readBoolean();
  int maxAge = deserializer.readInt();
  String name = deserializer.readString();
  String path = deserializer.readString();
  boolean secure = deserializer.readBoolean();
  String value = deserializer.readString();
  if (value.isEmpty()) {
    value = null;
  }
  int version = deserializer.readInt();
  Cookie cookie = new Cookie(name, value);
  if (!comment.isEmpty()) {
    cookie.setComment(comment);
  }
  if (!domain.isEmpty()) {
    cookie.setDomain(domain);
  }
  cookie.setHttpOnly(httpOnly);
  cookie.setMaxAge(maxAge);
  if (!path.isEmpty()) {
    cookie.setPath(path);
  }
  cookie.setSecure(secure);
  cookie.setVersion(version);
  return cookie;
}

代码示例来源:origin: mitre/HTTP-Proxy-Servlet

/**
 * Copy cookie from the proxy to the servlet client.
 * Replaces cookie path to local path and renames cookie to avoid collisions.
 */
protected void copyProxyCookie(HttpServletRequest servletRequest,
                HttpServletResponse servletResponse, String headerValue) {
 //build path for resulting cookie
 String path = servletRequest.getContextPath(); // path starts with / or is empty string
 path += servletRequest.getServletPath(); // servlet path starts with / or is empty string
 if(path.isEmpty()){
  path = "/";
 }
 for (HttpCookie cookie : HttpCookie.parse(headerValue)) {
  //set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
  String proxyCookieName = doPreserveCookies ? cookie.getName() : getCookieNamePrefix(cookie.getName()) + cookie.getName();
  Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
  servletCookie.setComment(cookie.getComment());
  servletCookie.setMaxAge((int) cookie.getMaxAge());
  servletCookie.setPath(path); //set to the path of the proxy servlet
  // don't set cookie domain
  servletCookie.setSecure(cookie.getSecure());
  servletCookie.setVersion(cookie.getVersion());
  servletCookie.setHttpOnly(cookie.isHttpOnly());
  servletResponse.addCookie(servletCookie);
 }
}

代码示例来源:origin: io.undertow/undertow-servlet

@Override
  public Cookie setComment(final String comment) {
    cookie.setComment(comment);
    return this;
  }
}

代码示例来源:origin: kz.greetgo.mvc/greetgo.mvc

@Override
 public CookieResponseSaver comment(String comment) {
  cookie.setComment(comment);
  return this;
 }
};

代码示例来源:origin: pippo-java/pippo

@Override
public void addResponseCookie(Cookie cookie) {
  getResponse().cookie(cookie.getPath(),
    cookie.getDomain(),
    cookie.getName(),
    cookie.getValue(),
    cookie.getMaxAge(),
    cookie.isSecure()
  );
  javax.servlet.http.Cookie addedCookie = getResponse().getCookie(cookie.getName());
  addedCookie.setHttpOnly(cookie.isHttpOnly());
  addedCookie.setComment(cookie.getComment());
}

代码示例来源:origin: br.com.jarch/jarch-crud

public static Cookie createCookie(HttpServletRequest request, HttpServletResponse response,
    String name, String value, String domain, String comment, int maxAge){
  Cookie cookie = new Cookie(name, value);
  cookie.setComment(comment);
  cookie.setMaxAge(maxAge);
  if (domain != null) {
    cookie.setDomain(domain);
  }
  response.addCookie(cookie);
  return cookie;
}

代码示例来源:origin: org.apereo.cas/cas-server-core-cookie-api

@Override
  protected Cookie createCookie(final String cookieValue) {
    val c = super.createCookie(cookieValue);
    c.setComment("CAS Cookie");
    return c;
  }
}

代码示例来源:origin: org.apereo.cas/cas-server-support-cookie

@Override
  protected Cookie createCookie(final String cookieValue) {
    final Cookie c = super.createCookie(cookieValue);
    c.setComment("CAS Cookie");
    return c;
  }
}

代码示例来源:origin: org.jvnet.hudson.winstone/winstone

public Object clone() {
  Cookie clone = new Cookie(this.name, this.value);
  clone.setComment(this.comment);
  clone.setDomain(this.domain);
  clone.setMaxAge(this.maxAge);
  clone.setSecure(this.secure);
  clone.setVersion(this.version);
  clone.setPath(this.path);
  return clone;
}

代码示例来源:origin: org.n52.security/52n-security-ssoservice

private void buildCookieClientData(String serverHostname, Cookie cookie) {
  // these settings are "static" and must be updated each time a cookie is read, because the data is not provided
  // by browser requests
  cookie.setMaxAge(m_cookieMaxAgeSeconds);
  cookie.setPath(m_cookiePath);
  cookie.setComment(m_cookieComment);
  String domain = removeDotPrefix(buildCookieDomain(serverHostname));
  if (domain != null && !domain.isEmpty()) {
    cookie.setDomain(domain);
  }
}

代码示例来源:origin: riotfamily/riot

protected Cookie createCookie(HttpServletRequest request) {
  Cookie cookie = new Cookie(name, getValue(request));
  if (domain != null) {
    cookie.setDomain(domain);
  }
  cookie.setPath(path);
  cookie.setMaxAge(maxAge);
  cookie.setSecure(secure);
  cookie.setVersion(version);
  cookie.setComment(comment);
  return cookie;
}

代码示例来源:origin: com.jwebmp.inject.extensions/guice-servlet

public ImmutableCookie(Cookie original) {
 super(original.getName(), original.getValue());
 super.setMaxAge(original.getMaxAge());
 super.setPath(original.getPath());
 super.setComment(original.getComment());
 super.setSecure(original.getSecure());
 super.setValue(original.getValue());
 super.setVersion(original.getVersion());
 if (original.getDomain() != null) {
  super.setDomain(original.getDomain());
 }
}

代码示例来源:origin: org.sonatype.sisu.inject/guice-servlet

public ImmutableCookie(Cookie original) {
 super(original.getName(), original.getValue());
 super.setMaxAge(original.getMaxAge());
 super.setPath(original.getPath());
 super.setComment(original.getComment());
 super.setSecure(original.getSecure());
 super.setValue(original.getValue());
 super.setVersion(original.getVersion());
 if (original.getDomain() != null) {
  super.setDomain(original.getDomain());
 }
}

代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.rt.ui.html

protected Cookie createPersistentSessionCookie(SessionCookieConfig config, HttpSession httpSession) {
 Cookie cookie = new Cookie(ObjectUtility.nvl(config.getName(), "JSESSIONID"), httpSession.getId());
 // The cookie must not expire too early so that it does not break the heart beat -> use a big max age.
 cookie.setMaxAge((int) TimeUnit.DAYS.toSeconds(365)); // 1 year
 cookie.setComment(config.getComment());
 if (config.getDomain() != null) {
  cookie.setDomain(config.getDomain());
 }
 cookie.setHttpOnly(config.isHttpOnly());
 cookie.setPath(config.getPath());
 cookie.setSecure(config.isSecure());
 return cookie;
}

代码示例来源:origin: org.jboss.resteasy/resteasy-test-tjws

public void addNewCookie(NewCookie cookie)
{
 Cookie cook = new Cookie(cookie.getName(), cookie.getValue());
 cook.setMaxAge(cookie.getMaxAge());
 cook.setVersion(cookie.getVersion());
 if (cookie.getDomain() != null) cook.setDomain(cookie.getDomain());
 if (cookie.getPath() != null) cook.setPath(cookie.getPath());
 cook.setSecure(cookie.isSecure());
 if (cookie.getComment() != null) cook.setComment(cookie.getComment());
 response.addCookie(cook);
}

相关文章