<%@ page import="java.util.*" %>
<%
Cookie[] cookies = request.getCookies();
if (cookies == null)
cookies = new Cookie[0];
Date thisVisit = new Date();
// add data cookie to session
Cookie c = new Cookie("lastVisit",""+thisVisit);
response.addCookie(c);
// add cookie to session
String name = request.getParameter("name");
String value = request.getParameter("value");
Cookie added = null;
if (name!=null && value!=null && name.length()>0) {
added = new Cookie(name,value);
response.addCookie(added);
}
%>
Cookie List
Cookie List
This visit: <%= thisVisit %>
Number of cookies: <%= cookies.length %>
Cookies
<%
for (int i=0; i out.println(cookies[i].getName()+":\t"+
cookies[i].getValue()+"
");
// check if added cookie already present
if (added!=null && added.getName().equals(cookies[i].getName()))
added = null;
}
if (added != null)
out.println("new cookie: "+added.getName()+":\t"+
added.getValue()+"
");
%>
New cookie
JSP-List-All-Cookie.zip( 88 k)