Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Saturday, December 1, 2007

java code for Setting and Reading Cookies



Setting and Reading Cookies


<%
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);
}
%>
>

Setting and Reading Cookies


This page will set its background color using a cookie.

No comments: