delete persistent cookie in java - help

L

Larry S

hello all - we're having one heck of a time trying to get cookies to
delete in the cookie file through java. Funny thing is, the code we're
using works fine on our local development environments, but when we
move it up to an environment more like our production, it only works
sometimes..
I've tried everything i've read, and still can't figure it out. i'm
hoping someone can shed some light on this. As always, any and all
help is greatly appreciated.

HOW WE'RE SETTING COOKIES:
protected void setCookie(String cookieName, String cookieValue)
{
//GET the cookie exp time / domain
String cookieExpDays =
CTPropertiesManager.getProperty("site.properties",

"site.cookie.expirytime");
String cookieDomain =
CTPropertiesManager.getProperty("site.properties",

"site.cookie.domain");

int expTimeInSeconds = 0;
if (cookieExpDays != null)
{
expTimeInSeconds = Integer.parseInt(cookieExpDays) * 24 *
60 * 60;
}

Cookie cookie = new Cookie(cookieName, cookieValue);

if (cookieDomain != null)
{
cookie.setDomain(cookieDomain);
cookie.setPath("/ct");
}

cookie.setMaxAge(expTimeInSeconds);
cookie.setSecure(false);

try
{
response.addCookie(cookie);
}
catch(Exception e)
{
CTLogManager.log(e);
}

}//end setCookie()

HOW WE'RE DELETING COOKIES:
protected void deleteCookie(String cookieName)
{
String cookieDomain =
CTPropertiesManager.getProperty("site.properties",

"site.cookie.domain");

try
{
//get all cookies
Cookie cookies[] = request.getCookies();

Cookie ctCookie=null;
if (cookies !=null)
{
for(int i=0; i<cookies.length; i++)
{
ctCookie=cookies;
if (ctCookie.getName().trim().equals(cookieName))
{
if ( cookieDomain != null )
{
ctCookie.setDomain(cookieDomain);
}

ctCookie.setPath("/ct");
ctCookie.setMaxAge(0);
response.addCookie(ctCookie);
}
}//end for
}//end if cookie
}//end try
catch(Exception e){
CTLogManager.log(e);
}
}//end deleteCookie()
 
S

Sudsy

Larry said:
hello all - we're having one heck of a time trying to get cookies to
delete in the cookie file through java. Funny thing is, the code we're
using works fine on our local development environments, but when we
move it up to an environment more like our production, it only works
sometimes..
I've tried everything i've read, and still can't figure it out. i'm
hoping someone can shed some light on this. As always, any and all
help is greatly appreciated.

Here's how I delete a cookie:

Cookie cart = new Cookie( "CART", null );
cart.setMaxAge( 0 );
resp.addCookie( cart );

Also, your wording concerns me. You say you still see the cookie
"in the cookie file". Perhaps your browser internally caches the
cookie jar and only writes it out when exiting?
 
L

Larry S

yep - we tried that - creating a new object, setting its age to zero,
and adding it. didn't work.
As far as the file, IE writes many little cookie files, one for each
domain. they dont delete until you hit the 'delete cookies' button in
IE 6, or delete the files in the web cache directory in IE 5. Netscape
writes the cookies into 1 big cookies.txt file, so those files are
what i mean.
I know it updates cookies just fine, but wont delete them. Heck, i
tried closing my browser, and reopening it, so test the theory about
weather it updated the files upon browser closing, and it STILL didn't
work. hmmm.
 
L

Larry S

incase your curious on the progress - it seems that our server time
stamps are off my 15 minutes... we're confident, that this may
negatively effect the cookies, and the expirations that we try to put
on them. this explains why it works locally, but not on any of our
environments.

Anyway - if anyone else has a similar problem, take a look at your
time stamps! :)
 
Joined
Mar 18, 2009
Messages
1
Reaction score
0
Request for more Info,

Hi Lerry,

I have the same problem as you had earlier.Could u please give an insight on how you resolved the Cookie problem.

I am enforcing the Cookie deletion too but still it does not work on the production environment

Thanks,
Sujitha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top