Cookie
存储在客户端上的小数据
会话cookie,关闭会话失效
持久化cookie设置存储时间
//设置cookie
Cookie cookie = new Cookie("name", "values");
//3600秒后失效,默认浏览器关闭失效
cookie .setMaxAge(3600);
//cookie.setValue("li");重置cookie的值
response.addCookie(cookie);
//当路径为www.wsy.com/CookieDemo/时才会携带cookie
cookie.setDomain(".wsy.com");
cookie.setPath("/CookieDemo");
//获取cookie
Cookie[] cookies = request.getCookies();
if(cookies != null){
for (Cookie cookie2 : cookies) {
String name = cookie2.getName();
String value = cookie2.getValue();
System.out.println(name + value);
}
}