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