当前位置: 首页>>代码示例>>Java>>正文


Java Cookie.getName方法代码示例

本文整理汇总了Java中javax.servlet.http.Cookie.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.getName方法的具体用法?Java Cookie.getName怎么用?Java Cookie.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.Cookie的用法示例。


在下文中一共展示了Cookie.getName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public String getCookie(HttpServletRequest request, String key) {
    Cookie[] cookies = request.getCookies();

    if (cookies == null) {
        return null;
    }

    for (Cookie cookie : cookies) {
        if ((cookie == null) || (cookie.getName() == null)) {
            continue;
        }

        if (cookie.getName().equals(key)) {
            return cookie.getValue();
        }
    }

    return null;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:20,代码来源:RememberLastUsernameAuthenticationSuccessHandler.java

示例2: createCookieMap

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 *
 * Creates the Map that maps cookie name to the first matching
 * Cookie in request.getCookies().
 **/
public static Map<String, Cookie> createCookieMap (PageContext pContext)
{
  // Read all the cookies and construct the entire map
  HttpServletRequest request = (HttpServletRequest) pContext.getRequest ();
  Cookie [] cookies = request.getCookies ();
  Map<String, Cookie> ret = new HashMap<String, Cookie> ();
  for (int i = 0; cookies != null && i < cookies.length; i++) {
    Cookie cookie = cookies [i];
    if (cookie != null) {
      String name = cookie.getName ();
      if (!ret.containsKey (name)) {
        ret.put (name, cookie);
      }
    }
  }
  return ret;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:ImplicitObjectELResolver.java

示例3: findCookieByName

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 获取指定cookies的值 findCookieByName
 * 
 * @param request
 * @param name
 * @return String
 */
public static String findCookieByName(HttpServletRequest request,
		String name) {
	Cookie[] cookies = request.getCookies();
	if(null == cookies || cookies.length == 0) return null;
	String string = null;
	try {
		for (int i = 0; i < cookies.length; i++) {
			Cookie cookie = cookies[i];
			String cname = cookie.getName();
			if (!StringUtils.isBlank(cname) && cname.equals(name)) {
				string = cookie.getValue();
			}

		}
	} catch (Exception ex) {
		logger.error("获取Cookies发生异常!", ex);
	}
	return string;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:27,代码来源:CookieUtil.java

示例4: getCookies

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static Map<String, String> getCookies(HttpServletRequest request) {
	Map<String, String> sCookie = new HashMap<>();
	Cookie[] cookies = request.getCookies();
	if (cookies != null) {
		String cookiePre = ConfigUtil.config.get("cookiePre");
		int prelength = Common.strlen(cookiePre);
		for (Cookie cookie : cookies) {
			String name = cookie.getName();
			if (name != null && name.startsWith(cookiePre)) {

				sCookie.put(name.substring(prelength), Common.urlDecode(Common.addSlashes(cookie.getValue())));
			}
		}
	}
	return sCookie;
}
 
开发者ID:shizicheng,项目名称:spring_mvc_template,代码行数:17,代码来源:CookieUtil.java

示例5: addSessionCookieInternal

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Special method for adding a session cookie as we should be overriding any
 * previous
 * 
 * @param cookie
 */
public void addSessionCookieInternal(final Cookie cookie) {
	if (isCommitted()) {
		return;
	}

	String name = cookie.getName();
	final String headername = "Set-Cookie";
	final String startsWith = name + "=";
	final StringBuffer sb = generateCookieString(cookie);
	boolean set = false;
	MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
	int n = headers.size();
	for (int i = 0; i < n; i++) {
		if (headers.getName(i).toString().equals(headername)) {
			if (headers.getValue(i).toString().startsWith(startsWith)) {
				headers.getValue(i).setString(sb.toString());
				set = true;
			}
		}
	}
	if (!set) {
		addHeader(headername, sb.toString());
	}

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:32,代码来源:Response.java

示例6: getCookieValue

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/***
 * 获取特定cookie的value
 * @param request web请求对象
 * @param cookieKey cookieKey
 * @return
 */
public static String getCookieValue(HttpServletRequest request,String cookieKey){
	Cookie[] cookies = request.getCookies();
	String cookieValue = "";
	if(!StringUtils.isBlank(cookieKey)){
		for (Cookie cookie : cookies) {
			String name = cookie.getName();
			if (cookieKey.equals(name)) {
				cookieValue = cookie.getValue();
				break;
			}
		}
	}
	return cookieValue;
}
 
开发者ID:tojaoomy,项目名称:private-WeChat,代码行数:21,代码来源:RequestUtils.java

示例7: addSessionCookieInternal

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Special method for adding a session cookie as we should be overriding
 * any previous
 * @param cookie
 */
public void addSessionCookieInternal(final Cookie cookie) {
    if (isCommitted()) {
        return;
    }

    String name = cookie.getName();
    final String headername = "Set-Cookie";
    final String startsWith = name + "=";
    final StringBuffer sb = generateCookieString(cookie);
    boolean set = false;
    MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
    int n = headers.size();
    for (int i = 0; i < n; i++) {
        if (headers.getName(i).toString().equals(headername)) {
            if (headers.getValue(i).toString().startsWith(startsWith)) {
                headers.getValue(i).setString(sb.toString());
                set = true;
            }
        }
    }
    if (!set) {
        addHeader(headername, sb.toString());
    }


}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:32,代码来源:Response.java

示例8: getStatusView

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Returns status view selection, if any, based on
 * parameters, the session or the cookie.
 */
private String getStatusView(final Parameters params, final HttpServletRequest request) {
  final HttpSession session = request.getSession();
  String statusView = params.getParameterValue(Pages.PARAM_STATUS_VIEW);

  if (StringUtils.isBlank(statusView)) {
    statusView = (String) session.getAttribute(ATTR_MERGE_STATUS_VIEW);
  }

  if (StringUtils.isBlank(statusView)) {
    String result = null;
    final Cookie[] cookies = request.getCookies();
    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        final Cookie cookie = cookies[i];
        final String cookieName = cookie.getName();
        final String cookieValue = cookie.getValue();
        if (!StringUtils.isBlank(cookieName)
                && cookieName.equals(COOKIE_MERGE_STATUS_VIEW)
                && !StringUtils.isBlank(cookieValue)) {
          result = cookieValue;
          break;
        }
      }
    }
    statusView = result;
  }
  return statusView;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:33,代码来源:MergeStatusesPage.java

示例9: doGet

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    for (Cookie cookie : req.getCookies()) {
        cookie.getName();
        cookie.getValue();
        cookie.getPath();
    }

    resp.addCookie(new Cookie("test", "value"));
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:11,代码来源:CookieUsage.java

示例10: deleteCookiesIfDoeasntExists

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static void deleteCookiesIfDoeasntExists(HttpServletRequest request, HttpServletResponse response) {
    for (Cookie x : request.getCookies()) {
        if (x.getName().equals("JSESSIONID"))
            continue;
        Cookie cookie = new Cookie(x.getName(), x.getValue());
        cookie.setMaxAge(0);
        response.addCookie(cookie);
    }
}
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:10,代码来源:CookiesDAO.java

示例11: toJaxRsCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
static javax.ws.rs.core.Cookie toJaxRsCookie(final Cookie cookie) {
    return new javax.ws.rs.core.Cookie(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain());
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:4,代码来源:CredentialFlowStateHelper.java

示例12: makeHttpRequest

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Override
protected HttpResponse makeHttpRequest(HttpBody entity, long startTime) {
    logger.info("making mock http client request: {} - {}", request.getMethod(), getRequestUri());
    MockHttpServletRequest req = requestBuilder.buildRequest(getServletContext());
    byte[] bytes;
    if (entity != null) {
        bytes = entity.getBytes();
        req.setContentType(entity.getContentType());
        if (entity.isMultiPart()) {
            for (MultiPartItem item : entity.getParts()) {
                MockMultiPart part = new MockMultiPart(item);
                req.addPart(part);
                if (!part.isFile()) {
                    req.addParameter(part.getName(), part.getValue());
                }
            }
        } else if (entity.isUrlEncoded()) {
            req.addParameters(entity.getParameters());
        } else {
            req.setContent(bytes);
        }
    } else {
        bytes = null;
    }
    MockHttpServletResponse res = new MockHttpServletResponse();
    logRequest(req, bytes);
    try {
        getServlet(request).service(req, res);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    long responseTime = getResponseTime(startTime);
    bytes = res.getContentAsByteArray();
    logResponse(res, bytes);
    HttpResponse response = new HttpResponse(responseTime);
    response.setUri(getRequestUri());
    response.setBody(bytes);
    response.setStatus(res.getStatus());
    for (Cookie c : res.getCookies()) {
        com.intuit.karate.http.Cookie cookie = new com.intuit.karate.http.Cookie(c.getName(), c.getValue());
        cookie.put(DOMAIN, c.getDomain());
        cookie.put(PATH, c.getPath());
        cookie.put(SECURE, c.getSecure() + "");
        cookie.put(MAX_AGE, c.getMaxAge() + "");
        cookie.put(VERSION, c.getVersion() + "");
        response.addCookie(cookie);
    }
    for (String headerName : res.getHeaderNames()) {
        response.putHeader(headerName, res.getHeaders(headerName));
    }
    return response;
}
 
开发者ID:intuit,项目名称:karate,代码行数:53,代码来源:MockHttpClient.java

示例13: encodeCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Encode a cookie as per RFC 2109.  The resulting string can be used
 * as the value for a <code>Set-Cookie</code> header.
 *
 * @param cookie The cookie to encode.
 * @return A string following RFC 2109.
 */
public static String encodeCookie(Cookie cookie) {

    StringBuffer buf = new StringBuffer( cookie.getName() );
    buf.append("=");
    buf.append(cookie.getValue());

    if (cookie.getComment() != null) {
        buf.append("; Comment=\"");
        buf.append(cookie.getComment());
        buf.append("\"");
    }

    if (cookie.getDomain() != null) {
        buf.append("; Domain=\"");
        buf.append(cookie.getDomain());
        buf.append("\"");
    }

    long age = cookie.getMaxAge();
    if (cookie.getMaxAge() >= 0) {
        buf.append("; Max-Age=\"");
        buf.append(cookie.getMaxAge());
        buf.append("\"");
    }

    if (cookie.getPath() != null) {
        buf.append("; Path=\"");
        buf.append(cookie.getPath());
        buf.append("\"");
    }

    if (cookie.getSecure()) {
        buf.append("; Secure");
    }

    if (cookie.getVersion() > 0) {
        buf.append("; Version=\"");
        buf.append(cookie.getVersion());
        buf.append("\"");
    }

    return (buf.toString());
}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:51,代码来源:RequestUtil.java

示例14: getCookieHeaderValue

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/** Return the header value used to set this cookie
 */
public static void getCookieHeaderValue(Cookie cookie, StringBuffer buf) {
    int version = cookie.getVersion();

    // this part is the same for all cookies

    String name = cookie.getName();     // Avoid NPE on malformed cookies
    if (name == null)
        name = "";
    String value = cookie.getValue();
    if (value == null)
        value = "";

    buf.append(name);
    buf.append("=");
    maybeQuote(version, buf, value);

    // add version 1 specific information
    if (version == 1) {
        // Version=1 ... required
        buf.append (";Version=1");

        // Comment=comment
        if (cookie.getComment() != null) {
            buf.append (";Comment=");
            maybeQuote (version, buf, cookie.getComment());
        }
    }

    // add domain information, if present

    if (cookie.getDomain() != null) {
        buf.append(";Domain=");
        maybeQuote (version, buf, cookie.getDomain());
    }

    // Max-Age=secs/Discard ... or use old "Expires" format
    if (cookie.getMaxAge() >= 0) {
        if (version == 0) {
            buf.append (";Expires=");
            if (cookie.getMaxAge() == 0)
                DateTool.oldCookieFormat.format(new Date(10000), buf,
                                                new FieldPosition(0));
            else
                DateTool.oldCookieFormat.format
                    (new Date( System.currentTimeMillis() +
                               cookie.getMaxAge() *1000L), buf,
                     new FieldPosition(0));
        } else {
            buf.append (";Max-Age=");
            buf.append (cookie.getMaxAge());
        }
    } else if (version == 1)
      buf.append (";Discard");

    // Path=path
    if (cookie.getPath() != null) {
        buf.append (";Path=");
        maybeQuote (version, buf, cookie.getPath());
    }

    // Secure
    if (cookie.getSecure()) {
      buf.append (";Secure");
    }
}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:68,代码来源:CookieTools.java


注:本文中的javax.servlet.http.Cookie.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。