| java.lang.Object com.oreilly.servlet.CookieParser
CookieParser | public class CookieParser (Code) | | A class to simplify cookie retrieval. It can retrieve cookie values by
name and return the value as any primitive type (no casting or parsing
required). It can also throw an exception when a cookie is not found
(simplifying error handling), and can accept default values (eliminating
error handling).
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();
}
See Also: com.oreilly.servlet.CookieNotFoundException author: Jason Hunter, Copyright © 2000 version: 1.0, 2000/03/19 |
Method Summary | |
public boolean | getBooleanCookie(String name) | public boolean | getBooleanCookie(String name, boolean def) Gets the named cookie value as a boolean, with a default. | public byte | getByteCookie(String name) | public byte | getByteCookie(String name, byte def) Gets the named cookie value as a byte, with a default. | public char | getCharCookie(String name) | public char | getCharCookie(String name, char def) Gets the named cookie value as a char, with a default. | public double | getDoubleCookie(String name) | public double | getDoubleCookie(String name, double def) Gets the named cookie value as a double, with a default. | public float | getFloatCookie(String name) | public float | getFloatCookie(String name, float def) Gets the named cookie value as a float, with a default. | public int | getIntCookie(String name) | public int | getIntCookie(String name, int def) Gets the named cookie value as a int, with a default. | public long | getLongCookie(String name) | public long | getLongCookie(String name, long def) Gets the named cookie value as a long, with a default. | public short | getShortCookie(String name) | public short | getShortCookie(String name, short def) Gets the named cookie value as a short, with a default. | public String | getStringCookie(String name) | public String | getStringCookie(String name, String def) Gets the named cookie value as a String, with a default. | void | parseCookies() |
CookieParser | public CookieParser(HttpServletRequest req)(Code) | | Constructs a new CookieParser to handle the cookies of the
given request.
Parameters: req - the servlet request |
getBooleanCookie | public boolean getBooleanCookie(String name, boolean def)(Code) | | Gets the named cookie value as a boolean, with a default.
Returns the default value if the cookie is not found.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a boolean, or the default |
getByteCookie | public byte getByteCookie(String name, byte def)(Code) | | Gets the named cookie value as a byte, with a default.
Returns the default value if the cookie is not found or cannot
be converted to a byte.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a byte, or the default |
getCharCookie | public char getCharCookie(String name, char def)(Code) | | Gets the named cookie value as a char, with a default.
Returns the default value if the cookie is not found.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a char, or the default |
getDoubleCookie | public double getDoubleCookie(String name, double def)(Code) | | Gets the named cookie value as a double, with a default.
Returns the default value if the cookie is not found.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a double, or the default |
getFloatCookie | public float getFloatCookie(String name, float def)(Code) | | Gets the named cookie value as a float, with a default.
Returns the default value if the cookie is not found.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a float, or the default |
getIntCookie | public int getIntCookie(String name, int def)(Code) | | Gets the named cookie value as a int, with a default.
Returns the default value if the cookie is not found.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a int, or the default |
getLongCookie | public long getLongCookie(String name, long def)(Code) | | Gets the named cookie value as a long, with a default.
Returns the default value if the cookie is not found.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a long, or the default |
getShortCookie | public short getShortCookie(String name, short def)(Code) | | Gets the named cookie value as a short, with a default.
Returns the default value if the cookie is not found.
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a short, or the default |
getStringCookie | public String getStringCookie(String name, String def)(Code) | | Gets the named cookie value as a String, with a default.
Returns the default value if the cookie is not found
Parameters: name - the cookie name Parameters: def - the default cookie value the cookie value as a String, or the default |
parseCookies | void parseCookies()(Code) | | |
|
|