添加cookie
导入包import="javax.servlet.http.Cookie"
Cookie cookie = new Cookie("username", user);
cookie.setMaxAge(300);
response.addCookie(cookie);
获取cookie
Cookie[] cookies = request.getCookies();
for(Cookie c :cookies ){
System.out.println(c.getName()+"--->"+c.getValue());
}
控制台输出结果如下:
username--->hzh
password--->123
JSESSIONID--->33BEAF95C526E0DDCF6A64990E533845