- 相关推荐
Java认证考试:如何设置和删除cookie
-
/**
* 删除cookie
*/
public static void clearCookie(HttpServletRequest request,HttpServletResponse response, String path) {
Cookie[] cookies = request.getCookies();
try{
for(int i=0;i《cookies.length;i++) {
//System.out.println(cookies[i]。getName() + “:” + cookies[i]。getValue());
Cookie cookie = new Cookie(cookies[i]。getName(), null);
cookie.setMaxAge(0);
cookie.setPath(path);//根据你创建cookie的路径进行填写
response.addCookie(cookie);
}
}catch(Exception ex) {
System.out.println(“删除Cookies发生异常!”);
}
}
public static void setCookie(HttpServletResponse response, String name, String value, String path) {
if (logger.isDebugEnabled()) {
logger.debug(“Setting cookie ‘” + name + “’ on path ‘” + path + “’”);
}
Cookie cookie = new Cookie(name, value);
cookie.setSecure(false);
cookie.setPath(path);
cookie.setMaxAge(Constants.COOKIE_INVALID_TIME);
response.addCookie(cookie);
// logger.info(“setCookie 完成……。”);
}
//调用
String cookiename = “vbo”;
String cookievalue = “cb”;
String path = “/”;
setCookie(response, cookiename , cookievalue , path);
clearCookie(request,response,path);//如果有name的话,方法也要增加name过去才能匹配
【Java认证考试:如何设置和删除cookie】相关文章:
php 删除cookie方法详解08-16
Linux认证考试科目设置07-27
Sun java认证考试答案10-23
java认证考试培训内容08-21
JAVA考试认证经验分享09-20
linux认证考试:FTP设置技巧08-17
Java认证考试的目的是什么09-19
oracle用户认证和密码设置技巧10-11
Java如何设置代理IP访问网站11-06
2016年Java认证考试题07-08