//File: createCookie.jsp
Setting a Cookie
Setting a Cookie
<%
Cookie cookie1 = new Cookie("message", "Hello!");
cookie1.setMaxAge(24 * 60 * 60);
response.addCookie(cookie1);
%>
Read the cookie
//File: readCookie.jsp
Reading a Cookie
Reading a Cookie
<%
Cookie[] cookies = request.getCookies();
for(int loopIndex = 0; loopIndex < cookies.length; loopIndex++) {
if (cookies[loopIndex].getName().equals("message")) {
out.println("The cookie says " + cookies[loopIndex].getValue());
}
}
%>
JspCreateReadCookie.zip( 89 k)