// cookieReader.jsp
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
We did not find any cookies in the request
The name and value of each found cookie
Cookie name:
Cookie value:
// cookieSetter.jsp
" />
" />
" />
Cookie Maker
Here is information about the new cookie
Name:
Value:
Path:
// put the class file to WEB-INF/classes/com/rntsoft
//CookieBean.java
package com.rntsoft;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
public class CookieBean {
private Cookie cookie = null;
public CookieBean() {
}
public void setName(String name) {
if (name == null || (name.equals("")))
throw new IllegalArgumentException("Invalid cookie name set in: "
+ getClass().getName());
cookie = new Cookie(name, "" + new java.util.Date().getTime());
}
public void setValue(String value) {
if (value == null || (value.equals("")))
throw new IllegalArgumentException("Invalid cookie value set in: "
+ getClass().getName());
if (cookie != null)
cookie.setValue(value);
}
public void setMaxAge(int maxAge) {
if (cookie != null)
cookie.setMaxAge(maxAge);
}
public void setPath(String path) {
if (path == null || (path.equals("")))
throw new IllegalArgumentException("Invalid cookie path set in: "
+ getClass().getName());
if (cookie != null)
cookie.setPath(path);
}
public void setCookieHeader(HttpServletResponse response) {
if (response == null)
throw new IllegalArgumentException(
"Invalid HttpServletResponse set in: "
+ getClass().getName());
if (cookie != null)
response.addCookie(cookie);
}
public String getName() {
if (cookie != null)
return cookie.getName();
else
return "unavailable";
}
public String getValue() {
if (cookie != null)
return cookie.getValue();
else
return "unavailable";
}
public String getPath() {
if (cookie != null)
return cookie.getPath();
else
return "unavailable";
}
}