Link to home
Start Free TrialLog in
Avatar of piou
piouFlag for Greece

asked on

Cookies attributes

I create a cookie, set a comment and an age, res.add(cookie)...
But when I read it at the next page, all attributes seem to be missing. Only name and value show up. The rest are null and -1 for max age... How come?

Avatar of piou
piou
Flag of Greece image

ASKER

Um, come to think of it, how can I tell if it's a session or a stored cookie? I can't find it anyway in the cookies directory (windows 2000), even if I don't close the browser.
Check your browser for cookie setting.  If the browser is not allowing the cookie, then you won't find anything.
Avatar of piou

ASKER

I have set "medium" level on IE, and I'm using lots of cookie sites (like EE) without problems.

Cookie c = new Cookie(name, value);
response.addCookie(c);

This way only you are adding rite.

Avatar of piou

ASKER

Yes, that's what I do.
Are you getting your cookies in the request.  Atleast few of your cookies that you set.

Can you post your servlet also
Avatar of piou

ASKER

Servlet1

Cookie cookie = new Cookie("databank", "username");
cookie.setComment("This is a test cookie");
cookie.setMaxAge(4000);
res.addCookie(cookie);

Servlet 2

Cookie[] cookies = req.getCookies();
if (cookies!=null) {
  for (int i=0; i<cookies.length; i++) {
  System.out.println(cookies[i].getName());
  System.out.println(cookies[i].getValue());
  System.out.println(cookies[i].getComment());
  System.out.println(cookies[i].getPath());
  System.out.println(cookies[i].getVersion());
  System.out.println(cookies[i].getDomain());
  System.out.println(cookies[i].getMaxAge());
  System.out.println(cookies[i].getSecure());
}

As simple as it can get :)

            } else {
                  System.out.println("No cookies set");
            }
Comment this

// cookie.setMaxAge(4000);

then use

cookie.setDomain("www.abc.com");

Try this.
ASKER CERTIFIED SOLUTION
Avatar of mmuruganandam
mmuruganandam
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of piou

ASKER

If running everything on localhost? Just "localhost"?
yep. use localhost
Avatar of piou

ASKER

No good. Result remains the same. I even set IE to the lowest privacy/security level.
It's so simple... what on earth am I missing?!

Avatar of piou

ASKER

Could it be the server itself? I'm using Tomcat 5 for the time being...
I donno about tomcat.  I have used cookies in websphere.  I have done that coding in this way only.

May be you can try some other server.
Avatar of piou

ASKER

If you're a Java person and you're sure we don't miss something, it's enough for me. Thanks!
http://cermics.enpc.fr/doc/java/j2eetutorial-1.4/doc/Admintool6.html

In that URL, check Table C-12 Context Properties


Try this one and let me know.
Avatar of piou

ASKER

Thanks for the link.

To be honest, I never had to run the J2EE server before. What happens is that the server starts ok, I can access the default page at port 8000, but the j2ee-admin page does not work at all; 404 error.

EE1.3, SE1.4