Source Code : Setting and Reading Cookies

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Setting and Reading Cookies

<HTML>
    <HEAD>
        <TITLE>Setting and Reading Cookies</TITLE>
    </HEAD>
 
    <BODY
        <%
        Cookie[] cookies = request.getCookies();
        boolean foundCookie = false;

        for(int i = 0; i < cookies.length; i++) { 
            Cookie c = cookies[i];
            if (c.getName().equals("color")) {
                out.println("bgcolor = " + c.getValue());
                foundCookie = true;
            }
        }  

        if (!foundCookie) {
            Cookie c = new Cookie("color", "cyan");
            c.setMaxAge(24*60*60);
            response.addCookie(c); 
        }
        %> 
        >
        <H1>Setting and Reading Cookies</H1>
        This page will set its background color using a cookie.
    </BODY>
</HTML>


           
       

Thank with us