How can I set a cookie and delete a cookie from within a JSP page?

A cookie, mycookie, can be deleted using the following scriptlet:<%//creating a cookieCookie mycookie = new Cookie("aName","aValue");response.addCookie(mycookie);//delete a cookieCookie killMyCookie = new Cookie("mycookie", null);killMyCookie.setMaxAge(0);killMyCookie.setPath("/");response.addCookie(killMyCookie);%>

Showing Answers 1 - 2 of 2 Answers

guna

  • May 18th, 2006
 

Can you plz explain what does each lines are doing?

  Was this answer useful?  Yes

<%
//creating a cookie
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
//delete a cookie
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
%>
?
In First line, We are creating cookie object of cookie class,
after that we are sending response to server.
we make object which take null value and it, setting life 0, after that we cookie send token to server, with null value, and max age 0.
then cookie have no life.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions