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()
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()