本文整理匯總了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"));
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
示例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";
}
示例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;
}
示例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;
}
示例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);
}
示例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");
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
}