Cookie userIdCookie = new Cookie("userId", "uid12345"); userIdCookie.setMaxAge(60*60*24*7); response.addCookie(userIdCookie);
String cookieName = "userId"; Cookie[] cookies = request.getCookies(); if(cookies != null){ for(int i=0; i<cookies.length; i++){ Cookie cookie = cookies[i]; if(cookieName.equals(cookie.getName())){ doSomeThing(cookie.getValue()); } } }