//发送session
request.getSession().setAttribute("user", "zs1");
//发送cookie
//需要自动登录,发送cookie
Cookie c_username=new Cookie("username",username);
Cookie c_password=new Cookie("password",password);
//设置存货时间
c_username.setMaxAge(60*60*24*7);
c_password.setMaxAge(60*60*24*7);
//发送cookie
response.addCookie(c_username);
response.addCookie(c_password);
//获取cookie
//2.1获取cookie,获取cookie中存储的用户名和密码
Cookie[] cs =req.getCookies();
String username=null;
String password=null;
if(cs !=null){
for (Cookie c : cs) {
String name = c.getName();
if("username".equals(name)){
username=c.getValue();
}
if("password".equals(name)){
password=c.getValue();
}
}
}