/*
* 写cookie
*/
Cookie namecookie = new Cookie("username",username);
Cookie passwordcookie = new Cookie("password",password);
//生命周期 一年
namecookie.setMaxAge(60*60*24*365);
passwordcookie.setMaxAge(60*60*24*365);
response.addCookie(namecookie);
response.addCookie(passwordcookie);
/*
* 读cookie
*/
Cookie[] cookies = request.getCookies();
if(cookies!=null)
{
String username = "";
String password = "";
for (int i = 0; i < cookies.length; i++)
{
Cookie c = cookies[i];
if(c.getName().equalsIgnoreCase("username "))
{
name = c.getValue();
}
else if(c.getName().equalsIgnoreCase("password"))
{
password = c.getValue();
}
}
}