?
Solved

my cookie is not getting

Posted on 2004-04-29
19
Medium Priority
?
354 Views
Last Modified: 2010-03-31
My cookie is not getting.  I use the below code to set a cookie the first time the page is requested then to get it on every subsequent request:

 String strAnswer= getCookie("UserCookieID", request);
   if (strNewUserCookieID != null){
   setCookie("UserCookieID", strNewUserCookieID, response);
   }


I'm confident my cookie is being set (because I can see it in the browsers cookie manager), the problem is that my getCookie function is always returning null.  Here are teh functions I use for getting and setting:

   <%!
   
    public void setCookie(String strName, String strValue, HttpServletResponse response)
    {
   
Cookie cooCookie = new Cookie(strName,strValue);
cooCookie.setMaxAge(50*365*24*60*60);
cooCookie.setPath("/");
response.addCookie(cooCookie);
rmhUtil.writeDebug(new Exception(),"cookie has been set:"+ cooCookie.getValue());

}
   %>
   
   <%!
   public String getCookie(String strName, HttpServletRequest request){
   
   String strAnswer=null;
   
   Cookie[] cookies = request.getCookies();
if (cookies != null)
{
  for (int i = 0; i < cookies.length; i++)
  {
     String name = cookies[i].getName();
     if (name==strName){
     strAnswer=cookies[i].getValue();
     }
   
  }
}

return strAnswer;

}
 %>  


can you please explain why my cookie is not 'getting' please??  - 500 points if you can.
0
Comment
Question by:rosshind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +2
19 Comments
 

Author Comment

by:rosshind
ID: 10950859
Its ok, I just realised the problem

I should have been using

 if (cookies[i].getName().equals(strName)){
     strAnswer=cookies[i].getValue();
     }

instead of == to compare the strings

First person to say hello gets 500 points!
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10950909
hello,

exactly you can use only...
.equals();

cookies[i].getName().equals(strName)...

R.K
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10952812
>> First person to say hello gets 500 points!
Why ? Just delete the question : you answered the question yourself, so you won the points.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 13

Expert Comment

by:Webstorm
ID: 10952817
You can ask to delete the question here : http://www.experts-exchange.com/Community_Support/askQuestion.jsp
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10955619
hello Webstorm,

 if he wants to give away the points , what is your difficulty...why unnecessarly spoiling the getting points,
he wants to give he is giving..then whats the problem...for you...

if u r the 1st person to say "hello"...what u will do..? i think its his decission, so leave him on his decission...

R.K
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10957702
Ram Krishna,

I would like to support Webstorm.

EE is supposed to be site where professionals and experts interact and exchange their knowledge and information. Its not merely an issue of getting the maximum points. You have probably not read the member agreement completely.

This page, after being PAQed, will be a resource and will be displayed in search results to other people who come looking to this site for solutions. They might not go through the whole page but might just click on the "See Solution" link, which will lead them to your comment - which was not the correct solution. The solution was found by the questioner himself.

rosshind,

I have always kept you in my list of good questioners (you can see that on my profile), and I hope you know that accepting comments which were not correct answers is against the member agreement. If you find the solution to a problem yourself, you should get the question deleted - a better way would be to get it PAQed with points refunded, in which case a moderator will close this question by refunding your points but it will not be deleted and it will be available in the knowledge-base for others to visit and see the correct solution.

Just a thought for your question's technical scope - you should also trim () the values - sometimes errors arise becasue of that (but of course, this depends on the scenario). You could also try equalsIgnoreCase () instead of equals ().

Mayank.
0
 

Author Comment

by:rosshind
ID: 10957971
Ok,

I didnt realise it was such an issue.  When I have some time I'll sort it out.  It would be a lot easier if there was an Accept button for my own question..
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958046
Well, you can't give points to yourself ;-) otherwise everybody could give too many points to themselves and be at the top ;-)

You should post a 0-point question in Community Support, give a link to this question and ask them to PAQ it, with points refunded. A moderator will close it (generally by accepting his own comment as an answer) and your points will be refunded. The question will stay in the knowledge-base for others to see if they come searching upon the same topic.
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10958294
Hi mayankeagle,

I will strongly appreciate your statements and comments.....
but..before that..

in u r statement u mentioned that..

>>> which will lead them to your comment - which was not the correct solution.
how can u say this statement,  please look at the answer first before you give any statement, i have provided the answer already... and if you talk about the Author comments, i don't care about what Author commented...

Finally i will leave this to the Author...????????

Thanks a lot....once again..
and best of luck..

R.K



0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958324
>> i have provided the answer already

No, you have not. You have repeated what the author said. He was himself the first person to post the solution.

>> i don't care about what Author commented

You have to ;-) because its his question. If he says that he has solved it himself, then it means that he has solved it. You can't falsify that by saying that you "don't care what the author says" and still try to repeat the answer by saying the same thing.
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10958492
thats authors wish...y you bother that..much...i dont; understand...????? as if u r issuing the points........

R.K
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958554
Rama Krishna,

The author's wish is not everything. In fact, he has also realized what is correct now. If you are a good member and have read the member agreement, then you would know what is correct and what is not. This is not the only question on EE. You will have many more to answer and take the points.
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10958559
i agreeee........awaiting for Author to Comment........????????????

R.K
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10970997
Recommendation: PAQ/ Refund.
0
 

Author Comment

by:rosshind
ID: 10986727
Look I'm really sorry for this, I dont want to upset anyone.  I have requested the points to be refunded back to me.

Sorry about the mix up.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10986996
Well, its ok with me.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10990066
Closed, 500 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 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