1.获取用户上次登陆的时间
Cookie cookies =request.getCookie();
boolean b=false;
if(cookies!=NULL){
for(Cookie cookie:cookies){
String name=cookie.getName();
if("lasttime".equals(name)){
out.println("上次登录时间为:"+cookie.value());
b=true;
SimpleDateFormat sdf=new SimpleDateFormat("...");
String time=sdf.format(java.util.Date());
cookie.setValue("lasttime", time);
cookie.setMaxAge(3600*24*7);
reponse.addCookie(cookie);
break;
}
}
}
if(!b){
out.println("您是第一次登陆!");
SimpleDateFormat sdf=new SimpleDateFormat("...");
String time=sdf.format(java.util.Date());
Cookie cookie=new Cookie("lasttime", time);
cookie.setMaxAge(3600*24*7);
response.addCookie(cookie);
}