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


Java Cookie.setValue方法代码示例

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


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

示例1: doGet

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    Cookie cookie = new Cookie("name", unknown());
    cookie.setValue(req.getParameter("p") + "x");
    resp.setHeader("header", req.getParameter("h1"));
    resp.addHeader("header", unknown());
    callCookieSink(req.getParameter("h2"));
    String encoded = ESAPI.encoder().encodeForURL(req.getParameter("h3"));
    resp.addHeader("header", ESAPI.encoder().decodeFromURL(encoded));
    
    // false positives
    String safe = "x".concat("y");
    Cookie safeCookie = new Cookie("name", safe);
    safeCookie.setValue(safe + "x");
    resp.setHeader("header", safe);
    resp.addHeader("header", encoded.concat(safe));


    HttpServletResponseWrapper resWrapper = new HttpServletResponseWrapper(resp);
    resWrapper.setHeader("header2",req.getParameter("a"));
    resWrapper.addHeader("header3",req.getParameter("b"));
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:23,代码来源:ResponseSplittingServlet.java

示例2: deleteCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static void deleteCookie(HttpServletRequest request, HttpServletResponse response,
        Cookie cookie, String domain, String path) {
    if (cookie != null) {
        if(StringUtils.isNotBlank(domain)){
            cookie.setDomain(domain);
        }
        cookie.setPath(path);
        cookie.setValue("");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
    }
}
 
开发者ID:bridgeli,项目名称:netty-socketio-demo,代码行数:13,代码来源:CookieUtils.java

示例3: setCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 设置 Cookie
 *
 * @param name   名称
 * @param value  值
 * @param maxAge 生存时间(单位秒)
 * @param path    路径
 */
public static void setCookie(HttpServletResponse response, String name, String value, String path, int maxAge) {
	Cookie cookie = new Cookie(name, null);
	cookie.setPath(path);
	cookie.setMaxAge(maxAge);
	try {
		cookie.setValue(URLEncoder.encode(value, "utf-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	response.addCookie(cookie);
}
 
开发者ID:funtl,项目名称:framework,代码行数:20,代码来源:CookieUtils.java

示例4: removeAllCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 销毁所有cookie
 * 
 * @param request
 * @param response
 */
public static void removeAllCookie(HttpServletRequest request, HttpServletResponse response) {
	Cookie[] cookies = request.getCookies();
	if (null != cookies) {
		for (int i = 0; i < cookies.length; i++) {
			Cookie cookie = cookies[i];
			cookie.setValue(null);
			cookie.setMaxAge(0);
			response.addCookie(cookie);
		}
	}
}
 
开发者ID:lemon-china,项目名称:lemon-framework,代码行数:18,代码来源:CookieUtil.java

示例5: exit

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@RequestMapping(value = "/exit")
public String exit(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
    Cookie[] cookies = httpServletRequest.getCookies();
    if(cookies != null){
        for(Cookie cookie : cookies){
            if(cookie.getName().equals("uid")){
                cookie.setValue(null);

            }else if(cookie.getName().equals("authen")){
                cookie.setValue(null);
            }
            cookie.setMaxAge(0);
            cookie.setPath("/");
            httpServletResponse.addCookie(cookie);
        }
    }
    return "redirect:/home";
}
 
开发者ID:zxbangban,项目名称:zxbangban,代码行数:19,代码来源:UserInfoController.java

示例6: delUserCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 删除cookie
 * 
 * @param request
 *            HttpServletRequest
 * @return Cookie信息
 */
public static Cookie delUserCookie(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (USER_COOKIE.equals(cookie.getName())) {
                cookie.setValue("");
                cookie.setMaxAge(0);
                return cookie;
            }
        }
    }
    return null;
}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:21,代码来源:CookieUtils.java

示例7: delCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/** 删除cookie */
public Cookie delCookie(HttpServletRequest request, String cookieName) {
	Cookie[] cookies = request.getCookies();
	if (cookies != null) {
		for (Cookie cookie : cookies) {
			if (cookieName.equals(cookie.getName())) {
				cookie.setValue("");
				cookie.setPath("/");
				cookie.setMaxAge(0);
				return cookie;
			}
		}
	}
	return null;
}
 
开发者ID:zhangjikai,项目名称:sdudoc,代码行数:16,代码来源:CookieUtil.java

示例8: setCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 设置 Cookie
 * @param name 名称
 * @param value 值
 * @param maxAge 生存时间(单位秒)
 * @param uri 路径
 */
public static void setCookie(HttpServletResponse response, String name, String value, String path, int maxAge) {
	Cookie cookie = new Cookie(name, null);
	cookie.setPath(path);
	cookie.setMaxAge(maxAge);
	try {
		cookie.setValue(URLEncoder.encode(value, "utf-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	response.addCookie(cookie);
}
 
开发者ID:NeilRen,项目名称:GeCMS,代码行数:19,代码来源:CookieUtils.java

示例9: createSession

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 创建cookie
 * @param response
 * @return
 */
@RequestMapping(value = "/create", method = RequestMethod.GET)
@ResponseBody
public PrevalentMessage createSession(HttpServletResponse response) {

    Cookie cookie = new Cookie("token", UUID.randomUUID().toString());
    cookie.setPath("/");
    cookie.setSecure(false);
    cookie.setHttpOnly(true);
    cookie.setMaxAge(86400);
    cookie.setValue("test");
    response.addCookie(cookie);

    return new PrevalentMessage("ok");
}
 
开发者ID:lordking,项目名称:spring-rest-sample,代码行数:20,代码来源:CrossDomainSessionController.java

示例10: setCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * 设置 Cookie
 * @param name 名称
 * @param value 值
 * @param maxAge 生存时间(单位秒)
 */
public static void setCookie(HttpServletResponse response, String name, String value, String path, int maxAge) {
	Cookie cookie = new Cookie(name, null);
	cookie.setPath(path);
	cookie.setMaxAge(maxAge);
	try {
		cookie.setValue(URLEncoder.encode(value, "utf-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	response.addCookie(cookie);
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:18,代码来源:CookieUtils.java

示例11: getCookies

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * @return
 * @Description Cookie内容过滤
 */
@Override
public Cookie[] getCookies() {
    Cookie[] existingCookies = super.getCookies();
    if (existingCookies != null) {
        for (int i = 0; i < existingCookies.length; ++i) {
            Cookie cookie = existingCookies[i];
            cookie.setValue(filterParamString(cookie.getValue()));
        }
    }
    return existingCookies;
}
 
开发者ID:T-baby,项目名称:ICEWall,代码行数:16,代码来源:ICEWallRequestWrapper.java

示例12: parseCookies

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Parse cookies.
 */
protected void parseCookies() {

    cookiesParsed = true;

    Cookies serverCookies = coyoteRequest.getCookies();
    int count = serverCookies.getCookieCount();
    if (count <= 0) {
        return;
    }

    cookies = new Cookie[count];

    int idx=0;
    for (int i = 0; i < count; i++) {
        ServerCookie scookie = serverCookies.getCookie(i);
        try {
            /*
            we must unescape the '\\' escape character
            */
            Cookie cookie = new Cookie(scookie.getName().toString(),null);
            int version = scookie.getVersion();
            cookie.setVersion(version);
            cookie.setValue(unescape(scookie.getValue().toString()));
            cookie.setPath(unescape(scookie.getPath().toString()));
            String domain = scookie.getDomain().toString();
            if (domain!=null)
             {
                cookie.setDomain(unescape(domain));//avoid NPE
            }
            String comment = scookie.getComment().toString();
            cookie.setComment(version==1?unescape(comment):null);
            cookies[idx++] = cookie;
        } catch(IllegalArgumentException e) {
            // Ignore bad cookie
        }
    }
    if( idx < count ) {
        Cookie [] ncookies = new Cookie[idx];
        System.arraycopy(cookies, 0, ncookies, 0, idx);
        cookies = ncookies;
    }

}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:47,代码来源:Request.java

示例13: updateResponse

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private void updateResponse(final Session session, final HttpServletResponse response) {
    Cookie c = new Cookie(SESSION_COOKIE, null);

    if (session == null) {
        c.setMaxAge(0);
    } else {
        c.setValue(session.getId());
    }

    c.setPath(ApiConfig.API_BASE);
    response.addCookie(c);
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:13,代码来源:SessionManagerImpl.java

示例14: removeCookie

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public void removeCookie(HttpServletRequest request, HttpServletResponse response, String key) {
    Cookie cookie = getCookieEntry(request, key);
    cookie.setValue(null);
    cookie.setMaxAge(0);
    response.addCookie(cookie);
}
 
开发者ID:codedrinker,项目名称:commenthub,代码行数:7,代码来源:BaseController.java

示例15: parseCookies

import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
 * Parse cookies.
 */
protected void parseCookies() {

	cookiesParsed = true;

	Cookies serverCookies = coyoteRequest.getCookies();
	int count = serverCookies.getCookieCount();
	if (count <= 0) {
		return;
	}

	cookies = new Cookie[count];

	int idx = 0;
	for (int i = 0; i < count; i++) {
		ServerCookie scookie = serverCookies.getCookie(i);
		try {
			/*
			 * we must unescape the '\\' escape character
			 */
			Cookie cookie = new Cookie(scookie.getName().toString(), null);
			int version = scookie.getVersion();
			cookie.setVersion(version);
			cookie.setValue(unescape(scookie.getValue().toString()));
			cookie.setPath(unescape(scookie.getPath().toString()));
			String domain = scookie.getDomain().toString();
			if (domain != null) {
				cookie.setDomain(unescape(domain));// avoid NPE
			}
			String comment = scookie.getComment().toString();
			cookie.setComment(version == 1 ? unescape(comment) : null);
			cookies[idx++] = cookie;
		} catch (IllegalArgumentException e) {
			// Ignore bad cookie
		}
	}
	if (idx < count) {
		Cookie[] ncookies = new Cookie[idx];
		System.arraycopy(cookies, 0, ncookies, 0, idx);
		cookies = ncookies;
	}

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


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