> Which servlet engine are you using? It can be a bug there. If you
> telnet to
> the web server and issue a request for the page you can see
> exactly what the
> Set-Cookie header returned by the server looks like. If I
> remember correctly
> it should look like
>
>   Set-Cookie foo=bar; expires="Thu, 01-Jan-1970 00:00:00 GMT"

I'm using JRun on NT with Netscape Enterprise 3.6.  The header I get for a
cookie with setMaxAge(0) is

Set-Cookie: TestCookie=TestValue; expires=Thu, 05-Nov-1998 22:35:50 GMT

when run at 15:35:50 MDT which is right.

Anyway, I was able to delete the cookies by using the following code:

    public void service(HttpServletRequest request, HttpServletResponse
response) throws
    ServletException, IOException {
        Cookie[] cookies = request.getCookies();

        PrintWriter out = response.getWriter();

        int numCookies = 0;
        Cookie cookie;
        if (cookies != null) {
          for (int i = 0; i < cookies.length; i++) {
            cookie = new Cookie(cookies[i].getName(), "");
            cookie.setMaxAge(0);
            cookie.setDomain(".my.domain");
            cookie.setPath("/");
            response.addCookie(cookie);
            numCookies++;
          }
        }

        response.setContentType("text/html");

        out.println("<html><head><title>ClearCookies</title></head><body>");
        out.println("<h2>ClearCookies</h2><hr>");

        out.println("<b>" + numCookies + " cookies have been deleted</b>");

        out.println("<hr></body></html>");

        out.close();
    }

The key seems to be setting the domain and the path properly which kinda
sucks since cookie.getPath() and cookie.getDomain() both seem to return
null.  Fortunately I know the appropriate values ahead of time.

-- Marc

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to