Popular Cookie

I am using Tomcat and Apache.

Tomcat which is the servlet container sends a cookie to the client.

I want to delete that cookie.

I am doing this.

Cookie[] lCookies = null;

lCookies = req.getCookies();

for(i=0;i<lCookies.length; i++){

if(lCookies.getName().equals("JSESSIONID")){

lCookies.setMaxAge(0);

res.addCookie(lCookies);

}

}

where res and req are HttpServletResponse and HttpServletRequest objects.

Does this delete that cookie?

If, someone knows about this, Please reply me soon

>

[629 byte] By [naveen_ind] at [2007-9-26 1:59:20]
# 1

Hi,

Here is a sample code to delete a cookie.

You can set the maximum age of a cookie with the cookie.setMaxAge(int seconds) method: Here are different options to this method,

Zero means to delete the cookie

A positive value is the maximum number of seconds the cookie will live, before it expires

A negative value means the cookie will not be stored beyond this browser session (deleted on browser close)

Here is a sample code to delete cookie.

private void deleteCookie(String cookieName)

{

Cookie[] cookies =request.getCookies();

if (cookies != null)

{

for (int i=0; i<cookies.length; i++)

{

if (cookies.getName().equals(cookieName));

cookies.setMaxAge(0);

}

}

}

I hope this will help you.

Thanks

Bakrudeen>

bakrudeen_indts at 2007-6-29 3:18:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...