At 03:32 PM 11/4/99 -0700, you wrote:

>So theoretically then the following code should work?
>
>public void service(HttpServletRequest request, HttpServletResponse
>response) throws ServletException, IOException {
>        Cookie[] cookies = request.getCookies();
>
>        PrintWriter out = response.getWriter();
>
>        response.setContentType("text/html");
>
>        if (cookies != null) {
>          for (int i = 0; i < cookies.length; i++) {
>            cookies[i].setMaxAge(0);
>            response.addCookie(cookies[i]);
>          }
>        }
>
>        out.println("<html><head><title>ClearCookies</title></head><body>");

I have always programmed response cookies as new cooie objects rather than
sharing references with the request cookie.  Hmm in fact the request cookie
will be a "Cookie" header whereas the response cookie is of the form
"Set-Cookie".  I think this will fix your problem:

  Cookies[] ca = request.getCookies();
  if( ca != null ) {
    for( int i = 0; i < ca.length; i++ ) {
      Cookie c = new Cookie( ca[i].getName(), ca[i].getValue() );
      c.setmaxAge( 0 );
      response.addCookie( c );
    }
}

Hope this helps...


Stuart

___________________________________________________________________________
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