本文整理汇总了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;
}
}