Solved

Cookies attributes

Posted on 2004-03-30
17
310 Views
Last Modified: 2013-11-23
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
Comment
Question by:piou
  • 9
  • 8
17 Comments
 

Author Comment

by:piou
ID: 10712019
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
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10712078
Check your browser for cookie setting.  If the browser is not allowing the cookie, then you won't find anything.
0
 

Author Comment

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

0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10712146
Cookie c = new Cookie(name, value);
response.addCookie(c);

This way only you are adding rite.

0
 

Author Comment

by:piou
ID: 10712155
Yes, that's what I do.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10712172
Are you getting your cookies in the request.  Atleast few of your cookies that you set.

Can you post your servlet also
0
 

Author Comment

by:piou
ID: 10712185
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
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10712203
Comment this

// cookie.setMaxAge(4000);

then use

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

Try this.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Accepted Solution

by:
mmuruganandam earned 50 total points
ID: 10712211
cookie.setDomain("<exactly your domain or IP>");

Browser exactly attaches the cookies to the corresponding website.
0
 

Author Comment

by:piou
ID: 10712220
If running everything on localhost? Just "localhost"?
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10712228
yep. use localhost
0
 

Author Comment

by:piou
ID: 10712247
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
 

Author Comment

by:piou
ID: 10712249
Could it be the server itself? I'm using Tomcat 5 for the time being...
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10712259
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
 

Author Comment

by:piou
ID: 10712274
If you're a Java person and you're sure we don't miss something, it's enough for me. Thanks!
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10712284
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
 

Author Comment

by:piou
ID: 10712405
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now