String userName="userId";
String password="123457899874512363314562589";
Cookie cookie=new Cookie(userName,password);
cookie.setMaxAge(10); //是10秒
cookie.setPath("http://localhost:8080/web/page/manager"); //表示当前页面下的page/manager/下的页面可以取到cookie中的值
response.addCookie(cookie);
Cookie[] cook=request.getCookies();
for(int i=0;i<cook.length;i++){
out.println("name:"+cook[i].getName()+"\tvalue:"+cook[i].getValue());
}