CookieUtilspublic class CookieUtils extends Object This class contains a number of static methods that can be used to
work with javax.servlet.Cookie objects. |
Methods Summary |
---|
public static java.lang.String | getCookieValue(java.lang.String name, javax.servlet.http.HttpServletRequest req)Returns the value of the Cookie with the specified name,
or null of not found.
Cookie[] cookies = req.getCookies();
String value = null;
for (int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals(name)) {
value = cookies[i].getValue();
break;
}
}
return value;
| public static boolean | isCookieSet(java.lang.String name, javax.servlet.http.HttpServletRequest req)Returns true if a cookie with the specified name is
present in the request.
return getCookieValue(name, req) != null;
| public static void | sendCookie(java.lang.String name, java.lang.String value, int maxAge, javax.servlet.http.HttpServletResponse res)Creates a Cookie with the specified name, value and max age,
and adds it to the response.
Cookie cookie = new Cookie(name, value);
cookie.setMaxAge(maxAge);
res.addCookie(cookie);
|
|