piou
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?
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?
Check your browser for cookie setting. If the browser is not allowing the cookie, then you won't find anything.
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.
response.addCookie(c);
This way only you are adding rite.
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
Can you post your servlet also
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].getNam e());
System.out.println(cookies [i].getVal ue());
System.out.println(cookies [i].getCom ment());
System.out.println(cookies [i].getPat h());
System.out.println(cookies [i].getVer sion());
System.out.println(cookies [i].getDom ain());
System.out.println(cookies [i].getMax Age());
System.out.println(cookies [i].getSec ure());
}
As simple as it can get :)
} else {
System.out.println("No cookies set");
}
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
System.out.println(cookies
System.out.println(cookies
System.out.println(cookies
System.out.println(cookies
System.out.println(cookies
System.out.println(cookies
System.out.println(cookies
}
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.
// cookie.setMaxAge(4000);
then use
cookie.setDomain("www.abc.com");
Try this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If running everything on localhost? Just "localhost"?
yep. use localhost
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?!
It's so simple... what on earth am I missing?!
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.
May be you can try some other server.
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.
In that URL, check Table C-12 Context Properties
Try this one and let me know.
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
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
ASKER