Tuesday, 5 April 2016

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


A cookie, mycookie, can be set / deleted using the following scriptlet : 

<%
    // 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);
%>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.