Java examples for Servlet JSP:Cookie
set Cookie in HttpServletResponse
import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Main{ public static void setCookie(HttpServletResponse response, String name, String value, Integer maxAgeSeconds) { Cookie cookie1 = new Cookie(name, value); if (maxAgeSeconds != null) cookie1.setMaxAge(maxAgeSeconds); response.addCookie(cookie1);//w w w . j av a2 s . c o m } }