set Cookie in HttpServletResponse - Java Servlet JSP

Java examples for Servlet JSP:Cookie

Description

set Cookie in HttpServletResponse

Demo Code


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
    }
}

Related Tutorials