- 相關推薦
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】相關文章:
java認證考試科目設置10-24
php 刪除cookie方法詳解10-24
JAVA認證考試細則06-10
java認證考試介紹07-31
Linux認證考試科目設置07-12
微軟認證考試科目設置07-16
sun java認證考試介紹10-23
JAVA認證考試費用06-25
java認證考試細則介紹08-19
Sun java認證考試答案11-06