01: package com.knowgate.http;
02:
03: /**
04: * <p>Cookies</p>
05: * <p>Company: KnowGate</p>
06: * @version 1.0
07: */
08:
09: import java.net.URLDecoder;
10: import javax.servlet.http.Cookie;
11: import javax.servlet.http.HttpServletRequest;
12:
13: public class Cookies {
14:
15: public static String getCookie(HttpServletRequest req,
16: String sName, String sDefault) {
17: Cookie aCookies[] = req.getCookies();
18: String sValue = null;
19:
20: for (int c = 0; c < aCookies.length; c++) {
21: if (aCookies[c].getName().equals(sName)) {
22: sValue = URLDecoder.decode(aCookies[c].getValue());
23: break;
24: } // fi(aCookies[c]==sName)
25: } // next(c)
26: return sValue != null ? sValue : sDefault;
27: } // getCookie()
28: } // Cookies
|