01: package com.technoetic.xplanner.util;
02:
03: import javax.servlet.http.*;
04:
05: /**
06: * User: Mateusz Prokopowicz
07: * Date: Jun 13, 2005
08: * Time: 12:15:00 PM
09: */
10: public class CookieSupport {
11: public static void createCookie(String name, String value,
12: HttpServletResponse response) {
13: Cookie cookie = new Cookie(name, value);
14: cookie.setMaxAge(Integer.MAX_VALUE);
15: response.addCookie(cookie);
16: }
17:
18: public static void deleteCookie(String name,
19: HttpServletResponse response) {
20: Cookie cookie = new Cookie(name, "");
21: cookie.setMaxAge(0);
22: response.addCookie(cookie);
23: }
24:
25: public static Cookie getCookie(String name,
26: HttpServletRequest request) {
27: Cookie[] cookies = request.getCookies();
28: if (cookies != null) {
29: for (int i = 0; i < cookies.length; i++) {
30: Cookie cookie = cookies[i];
31: if (cookie.getName().equals(name)) {
32: return cookie;
33: }
34: }
35: }
36: return null;
37: }
38: }
|