• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

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?

0
piou
Asked:
piou
  • 9
  • 8
1 Solution
 
piouAuthor Commented:
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.
0
 
mmuruganandamCommented:
Check your browser for cookie setting.  If the browser is not allowing the cookie, then you won't find anything.
0
 
piouAuthor Commented:
I have set "medium" level on IE, and I'm using lots of cookie sites (like EE) without problems.

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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

This way only you are adding rite.

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

Can you post your servlet also
0
 
piouAuthor Commented:
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");
            }
0
 
mmuruganandamCommented:
Comment this

// cookie.setMaxAge(4000);

then use

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

Try this.
0
 
mmuruganandamCommented:
cookie.setDomain("<exactly your domain or IP>");

Browser exactly attaches the cookies to the corresponding website.
0
 
piouAuthor Commented:
If running everything on localhost? Just "localhost"?
0
 
mmuruganandamCommented:
yep. use localhost
0
 
piouAuthor Commented:
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?!

0
 
piouAuthor Commented:
Could it be the server itself? I'm using Tomcat 5 for the time being...
0
 
mmuruganandamCommented:
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.
0
 
piouAuthor Commented:
If you're a Java person and you're sure we don't miss something, it's enough for me. Thanks!
0
 
mmuruganandamCommented:
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.
0
 
piouAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now