Refresh to see the Cookie : Cookie « JSP « Java Tutorial






<HTML>
    <HEAD>
        <TITLE>Reading a Cookie</TITLE>
    </HEAD>  

    <BODY>
        <H1>Reading a Cookie</H1>  
  
        <%
        Cookie cookie1 = new Cookie("message", "Hello!");
        cookie1.setMaxAge(24 * 60 * 60);
        response.addCookie(cookie1); 
        %> 
        <P>refresh to see the Cookie</p> 
        <%
        Cookie[] cookies = request.getCookies();
    
        for(int i = 0; i < cookies.length; i++) { 
            if (cookies[i].getName().equals("message")) {
                out.println("The cookie says " + cookies[i].getValue());
            }
        }  
        %>
    </BODY>  
</HTML>








23.38.Cookie
23.38.1.Create Cookie
23.38.2.Refresh to see the Cookie
23.38.3.Setting and Reading Cookies