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


Java Cookie.getPath方法代码示例

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


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

示例1: getCookieByName

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static String getCookieByName(HttpServletRequest req,String name,String path) {
    Cookie[] cookies = req.getCookies();
    if(cookies == null){
        return null;
    }
    for(Cookie cookie:cookies){
        String cookiePath = cookie.getPath();
        if(cookiePath==null || "".equals(cookiePath)){
            cookiePath = "/";
        }

        if(name.equals(cookie.getName()) &&
                (path ==null || path.equals(cookiePath))){
            return cookie.getValue();
        }
    }
    return null;
}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:19,代码来源:HttpUtil.java

示例2: getValidUserName

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static String getValidUserName(HttpServletRequest req){
    Cookie[] cookies = req.getCookies();
    if(cookies==null){
        return null;
    }
    String nowUser = "", nowToken = "";
    try {
        for (Cookie cookie : cookies) {
            String path = cookie.getPath();
            boolean isRootPath = path == null || path.equals("/");
            if (cookie.getName().equals(USERKEY) && isRootPath){
                nowUser = cookie.getValue();
            } else if (cookie.getName().equals(TOKENKEY) && isRootPath){
                nowToken = cookie.getValue();
            }
        }
        return getValidUserName(nowUser,nowToken,HttpUtil.getIpAddr(req));
    }catch (Throwable e){
        return null;
    }

}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:23,代码来源:SecurityUtil.java

示例3: addCookieHeader

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private void addCookieHeader() {
    if (_cookies.isEmpty()) return;

    StringBuffer sb = new StringBuffer();
    for (Enumeration e = _cookies.elements(); e.hasMoreElements();) {
        Cookie cookie = (Cookie) e.nextElement();
        sb.append( cookie.getName() ).append( '=' ).append( cookie.getValue() );
        if (cookie.getPath() != null) sb.append( ";path=" ).append( cookie.getPath() );
        if (cookie.getDomain() != null) sb.append( ";domain=" ).append( cookie.getDomain() );
        if (e.hasMoreElements()) sb.append( ',' );
    }
    setHeader( "Set-Cookie", sb.toString() );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ServletUnitHttpResponse.java

示例4: 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

示例5: 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

示例6: 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

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