FileDocCategorySizeDatePackage
CookieUtils.javaAPI DocExample1423Tue Feb 28 11:34:06 GMT 2006com.ora.jsp.util

CookieUtils

public class CookieUtils extends Object
This class contains a number of static methods that can be used to work with javax.servlet.Cookie objects.
author
Hans Bergsten, Gefion software
version
2.0

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringgetCookieValue(java.lang.String name, javax.servlet.http.HttpServletRequest req)
Returns the value of the Cookie with the specified name, or null if not found.

        Cookie[] cookies = req.getCookies();
	if (cookies == null) {
	    return null;
	}

        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 booleanisCookieSet(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 voidsendCookie(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);