Cookies
<%
Cookie[] allCookies = request.getCookies();
Cookie ourCookie = null;
if (allCookies!=null)
{
for (int i=0; i
if (allCookies[i].getName().equals("TestCookie"))
{
ourCookie = allCookies[i];
}
}
}
if (ourCookie == null)
{
Cookie cookie = new Cookie("TestCookie", "hello from cookie");
//cookie.setMaxAge(1800);
//cookie.setDomain("alex:8080");
cookie.setPath("/");
response.addCookie(cookie);
%>
A cookie has been added to your machine!
Select refresh to see the details of this cookie.
<%
}
else
{
%>
The following cookie was added earlier to your machine:
Version: <%=ourCookie.getVersion() %>
Name: <%=ourCookie.getName() %>
Value: <%=ourCookie.getValue() %>
MaxAge: <%=ourCookie.getMaxAge() %>
<%
}
%>


No comments:
Post a Comment