Sending Cookies to Browser
Standard approach:
Cookie c = new Cookie("name", "value");
c.setMaxAge(...); // Means cookie persists on disk
// Set other attributes.
response.addCookie(c);
Simplified approach:
Use LongLivedCookie class:
public class LongLivedCookie extends Cookie {
public static final int SECONDS_PER_YEAR =
60*60*24*365;
public LongLivedCookie(String name, String value) {
super(name, value);
setMaxAge(SECONDS_PER_YEAR);
}
}
75
Servlets
www.corewebprogramming.com
Reading Cookies from Browser
Standard approach:
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for(int i=0; i
Cookie c = cookies[i];
if (c.getName().equals("someName")) {
doSomethingWith(c);
break;
}
}
}
Simplified approach:
Extract cookie or cookie value from cookie array 
by using ServletUtilities.getCookieValue or 
ServletUtilities.getCookie
76
Servlets
www.corewebprogramming.com
38




  

Home

About Services Network Support FAQ Order Contact
 

Servlet Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved