When creating a cookie without setting its path, the path defaults to the
path of the request, e.g., /myapp/ActionA.  The browser will not send the
cookie back for subsequent request for anything other than /myapp/ActionA.
Set the cookie path via cookie.setPath() to something that will allow the
browser to send the cookie back on subsequent requests - either to something
like cookie.setPath("/") or cookie.setPath("/myapp").

Regards,
George.

-----Original Message-----
From: Brian Holzer [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 06, 2002 6:50 PM
Subject: Struts and cookies


Hi all,
   I am hoping that this is an easy question.  I have ActionA, jspA and
ActionB.  In ActionA I add a cookie to the response passed into the
perform() method.

     Cookie cookie1 = new Cookie( "SGI", "autodev01" );
     response.addCookie( cookie1 );

  Then I exit ActionA with the following command

     return( mapping.findForward( fwd ) ); 

I am then forwarded to jspA where I enter some search criteria and press the
submit button which forwards to ActionB.  In ActionB I use some displays to
show the contents of the request passed into the perform() method 

      System.out.println( "OUTPUTTING HEADERS: " );
        Enumeration enum = request.getHeaderNames();
        while ( enum.hasMoreElements() ) {
           String k = (String) enum.nextElement();
           Object v = request.getHeader( k );
           System.out.println( "Key: " + k + "  Value: " + v.toString() );
        } // end of while

     Cookie sgiCookie[] = request.getCookies();
     System.out.println( "OUTPUTTING COOKIES: " );
     int w = 0;
     while( w < sgiCookie.length ){
        System.out.println( "Cookie number " + w );
        System.out.println( "Cookie name: " + sgiCookie[w].getName() );
        System.out.println( "Cookie value: " + sgiCookie[w].getValue() );
        System.out.println( "---------------------------" );
        w++;
     }

but the cookie I added is not there.  The only cookie still there is the
jsessionid cookie.  I am using Silverstream 3.7.3 app server.

Does anyone know why my cookie is dissappearing?  or am I somehow not adding
it in the right place? 

Thanks
Brian


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to