public class CookieParser
extends java.lang.Object
It is used like this:
CookieParser parser = new CookieParser(req);
float ratio = parser.getFloatCookie("ratio", 1.0);
int count = 0;
try {
count = parser.getIntCookie("count");
}
catch (NumberFormatException e) {
handleMalformedCount();
}
catch (CookieNotFoundException e) {
handleNoCount();
}
CookieNotFoundException| Constructor and Description |
|---|
CookieParser(javax.servlet.http.HttpServletRequest req)
Constructs a new CookieParser to handle the cookies of the
given request.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
getBooleanCookie(java.lang.String name)
Gets the named cookie value as a boolean
|
boolean |
getBooleanCookie(java.lang.String name,
boolean def)
Gets the named cookie value as a boolean, with a default.
|
byte |
getByteCookie(java.lang.String name)
Gets the named cookie value as a byte
|
byte |
getByteCookie(java.lang.String name,
byte def)
Gets the named cookie value as a byte, with a default.
|
char |
getCharCookie(java.lang.String name)
Gets the named cookie value as a char
|
char |
getCharCookie(java.lang.String name,
char def)
Gets the named cookie value as a char, with a default.
|
double |
getDoubleCookie(java.lang.String name)
Gets the named cookie value as a double
|
double |
getDoubleCookie(java.lang.String name,
double def)
Gets the named cookie value as a double, with a default.
|
float |
getFloatCookie(java.lang.String name)
Gets the named cookie value as a float
|
float |
getFloatCookie(java.lang.String name,
float def)
Gets the named cookie value as a float, with a default.
|
int |
getIntCookie(java.lang.String name)
Gets the named cookie value as a int
|
int |
getIntCookie(java.lang.String name,
int def)
Gets the named cookie value as a int, with a default.
|
long |
getLongCookie(java.lang.String name)
Gets the named cookie value as a long
|
long |
getLongCookie(java.lang.String name,
long def)
Gets the named cookie value as a long, with a default.
|
short |
getShortCookie(java.lang.String name)
Gets the named cookie value as a short
|
short |
getShortCookie(java.lang.String name,
short def)
Gets the named cookie value as a short, with a default.
|
java.lang.String |
getStringCookie(java.lang.String name)
Gets the named cookie value as a String
|
java.lang.String |
getStringCookie(java.lang.String name,
java.lang.String def)
Gets the named cookie value as a String, with a default.
|
public CookieParser(javax.servlet.http.HttpServletRequest req)
req - the servlet requestpublic java.lang.String getStringCookie(java.lang.String name)
throws CookieNotFoundException
name - the cookie nameCookieNotFoundException - if the cookie was not foundpublic java.lang.String getStringCookie(java.lang.String name,
java.lang.String def)
name - the cookie namedef - the default cookie valuepublic boolean getBooleanCookie(java.lang.String name)
throws CookieNotFoundException
name - the cookie nameCookieNotFoundException - if the cookie was not foundpublic boolean getBooleanCookie(java.lang.String name,
boolean def)
name - the cookie namedef - the default cookie valuepublic byte getByteCookie(java.lang.String name)
throws CookieNotFoundException,
java.lang.NumberFormatException
name - the cookie nameCookieNotFoundException - if the cookie was not foundjava.lang.NumberFormatException - if the cookie value could not
be converted to a bytepublic byte getByteCookie(java.lang.String name,
byte def)
name - the cookie namedef - the default cookie valuepublic char getCharCookie(java.lang.String name)
throws CookieNotFoundException
name - the cookie nameCookieNotFoundException - if the cookie was not foundpublic char getCharCookie(java.lang.String name,
char def)
name - the cookie namedef - the default cookie valuepublic double getDoubleCookie(java.lang.String name)
throws CookieNotFoundException,
java.lang.NumberFormatException
name - the cookie nameCookieNotFoundException - if the cookie was not foundjava.lang.NumberFormatException - if the cookie could not be converted
to a doublepublic double getDoubleCookie(java.lang.String name,
double def)
name - the cookie namedef - the default cookie valuepublic float getFloatCookie(java.lang.String name)
throws CookieNotFoundException,
java.lang.NumberFormatException
name - the cookie nameCookieNotFoundException - if the cookie was not foundjava.lang.NumberFormatException - if the cookie could not be converted
to a floatpublic float getFloatCookie(java.lang.String name,
float def)
name - the cookie namedef - the default cookie valuepublic int getIntCookie(java.lang.String name)
throws CookieNotFoundException,
java.lang.NumberFormatException
name - the cookie nameCookieNotFoundException - if the cookie was not foundjava.lang.NumberFormatException - if the cookie could not be converted
to a intpublic int getIntCookie(java.lang.String name,
int def)
name - the cookie namedef - the default cookie valuepublic long getLongCookie(java.lang.String name)
throws CookieNotFoundException,
java.lang.NumberFormatException
name - the cookie nameCookieNotFoundException - if the cookie was not foundjava.lang.NumberFormatException - if the cookie could not be converted
to a longpublic long getLongCookie(java.lang.String name,
long def)
name - the cookie namedef - the default cookie valuepublic short getShortCookie(java.lang.String name)
throws CookieNotFoundException,
java.lang.NumberFormatException
name - the cookie nameCookieNotFoundException - if the cookie was not foundjava.lang.NumberFormatException - if the cookie could not be converted
to a shortpublic short getShortCookie(java.lang.String name,
short def)
name - the cookie namedef - the default cookie value