當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。