Cookie cookie=new Cookie(“username”,“zhang”);
cookie.setPath("/");
cookie.setMaxAge(Integer.MAX_VALUE);
response.addCookie(cookie);
Cookie cookies[]=request.getCookies();
if(cookies!=null){
for(Cookie cook:cookies){
if(cook.getName().equals("username")){
out.print(cook.getValue());
}
}