Re: WOCookie - replacing/removing?
Re: WOCookie - replacing/removing?
- Subject: Re: WOCookie - replacing/removing?
- From: Benjamin Miller <email@hidden>
- Date: Wed, 3 Mar 2004 14:21:11 +0000
You can get the cookie sent by the browser from the WORequest - using
context().request() from a component. I normally send an expired cookie
with the same path and name to the browser to remove a cookie.
------
public void appendToResponse(WOResponse response, WOContext context) {
if (saveSettings()) {
// save the user's email address
WOCookie emailCookie = new WOCookie( "email",
(String)session.user.preferences().valueForKey("kWSLoginEmailAddress")
);
emailCookie.setPath("/");
// set the expiration date
NSTimestamp expires = new
NSTimestamp().timestampByAddingGregorianUnits(1, 0, 0, 0, 0, 0);
emailCookie.setExpires(expires);
// add the cookie to the response
response.addCookie(emailCookie);
} else {
// send expired cookies to clear the older cookies from the user's disk
as they do not want to save login settings
WOCookie emailCookie = new WOCookie("email", "none");
emailCookie.setPath("/");
// set the expiration date to a year ago
NSTimestamp expires = new
NSTimestamp().timestampByAddingGregorianUnits(-1, 0, 0, 0, 0, 0);
emailCookie.setExpires(expires);
// add the cookie
response.addCookie(emailCookie);
}
super.appendToResponse(response, context);
}
Benjamin
On Wednesday, March 3, 2004, at 01:50 pm,
email@hidden wrote:
> Once I add a cookie, and it gets stored on the browser, can I replace
> it
> with a new value or remove it and re-add it? Not sure how to do this.
> Have
> seen the removeCookie(WOCookie cookie) method, but is this what I
> need, and
> if so, how do I get the WOCookie to pass to this?
Benjamin Miller, Digital Developer
Watershed Media Centre
1 Canon's Road, Harbourside, Bristol, UK. BS1 5TX
t: +44 (0)117 927 6444, f: +44(0)117 921 3958
http://www.watershed.co.uk
iChat/AIM: email@hidden
--
What's a meaningful and engaging web experience?
Join in the debate at - http://www.dshed.net/digest
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.