I looked over your code. You might try this.

//set expiration date 1 days
    c.setMaxAge(1*24*6300);

should be c.setMaxAge(60*60*24) // 60 sec * 60 min * 24 hrs.

 for (int i = 0; i < cookies.length; i++)
        {
            System.out.println("cookies[i]: " + cookies[i]);
            System.out.println("cookies[i].getName(): " +
cookies[i].getName());
            workCookie = (Cookie)cookies[i].clone();
            if(workCookie.getName().equals(cookiesName))
            {
                returnValue = workCookie.getValue();
                return returnValue;
            }
        }

                TRY
                        String value = null;
                        for (int i =0; i < anyCookies.length; i++) {
                        if (anyCookies[i].getName().equals("YOUR_COOKIE);
                                value = anyCookies[i].getValue();
                                System.out.println("This is YOUR_COOKIE date " + value)
                        }

Tom Kochanowicz
[EMAIL PROTECTED]

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Meng,
Dong J (CAP, CDI)
Sent: Thursday, September 16, 1999 8:21 AM
To: [EMAIL PROTECTED]
Subject: lost session and cookies


Hi:

Recently, I am coding servlets pages. I have two pages, one is Logon.class,
another is Report.class. After customer logon, Logon will call Report.
At first, I put two page on the servlet root directory, I put customer
personal information into session in Logon.class, when XXX.com/servlet/Logon
calls XXX.com/servlet/Report, Report will get personal information from
session and HTML variables from Logon and present customer report. It works.
Then, I created one directory called fsleads under servlet root directory. I
moved Logon.java and Report.java to fsleads and treat these java files as a
package called fsleads. then I use XXX.com/servlet/fsleads.Logon to call
XXX.com/servlet/fsleads.Report. I can pass HTML variables to fsleads.Report,
but the session includes personal information lost. Do you know why?

After that, I tried to use cookies. I put customer personal information into
cookies in fsleads.Logon
The code is the following
  public void setCookies(HttpServletResponse res, String cookiesName, String
cookiesValue)
  {
    System.out.println("cookiesName: " + cookiesName);
    System.out.println("cookiesValue: " + cookiesValue);

    Cookie c = new Cookie(cookiesName, cookiesValue);
    c.setPath("/");
    //set expiration date 1 days
    c.setMaxAge(1*24*6300);
    res.addCookie(c);
  }
Then I tried to get cookies in fsleads.Report. The code is the following:
  public String getCookies(HttpServletRequest req, String cookiesName)
  {
    String returnValue = null;

    Cookie cookies[], workCookie = null;
    cookies = req.getCookies();
    if (cookies != null)
    {
        for (int i = 0; i < cookies.length; i++)
        {
            System.out.println("cookies[i]: " + cookies[i]);
            System.out.println("cookies[i].getName(): " +
cookies[i].getName());
            workCookie = (Cookie)cookies[i].clone();
            if(workCookie.getName().equals(cookiesName))
            {
                returnValue = workCookie.getValue();
                return returnValue;
            }
        }
    }

I can not get cookies in fsleads.Report. Do you what's wrong? Is it a wrong
cookies path?

Thanks in advance.

DJ

___________________________________________________________________________
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

___________________________________________________________________________
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