cook,session

//发送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();
}

}
}

posted @ 2019-09-03 00:56  享尔正  阅读(169)  评论(0编辑  收藏  举报