Java examples for Servlet JSP:Cookie
add Cookie to HttpServletResponse
import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Main{ public static void addCookie(String name, String value, int age, HttpServletResponse response) { Cookie cookies = new Cookie(name, value); cookies.setPath("/"); cookies.setMaxAge(age);/*w w w . j av a 2 s . co m*/ response.addCookie(cookies); } public static void addCookie(String name, String value, HttpServletResponse response) { addCookie(name, value, 60 * 60 * 24, response); } }