• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting The Value From A Cookie To Use In An If Statement  RSS feed

 
Nick Le Boutillier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

Sorry I'm a Newbie to Java and this site so please go easy on me.

I'm trying to display different content based upon the value stored within a hit counting cookie I already stored and working.

I'm sure the top part of this code will look familiar however my problem is getting the "hitno" cookie value to be able to use in the if statements below.



//I also tryed this as I thought the value might need to be converted from a string to an int - h_value = Integer.parseInt(myCookie.getValue())


//however I'd like to do something along the lines of the below displaying a message based upon the number of hits


Many Thanks for your time
[ May 20, 2008: Message edited by: Ulf Dittmer ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Which part of the code is working? Is the cookie found? Is the value correct? Can you convert it from a string to an int? You only told us what you tried, but not what the result was.
 
Nick Le Boutillier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I could have been a little more forthcoming with information.

I already have a working cookie called "hitno" tha stores the number of times a user visits the page.

I was then trying to use the code I posted to retrieve the value from the cookie and do a series of if statements to display content based upon the value in the cookie

So far the code below works



I can display the value of the cookie using



And I can use the above to display the cookie value if it's not null

What I can't seem to workout is how to myCookie.getValue() into and Int that I can use as an argument in an If statement further down the page.

I have tried h_value = cookies[i].getValue(); as stated in the main post but not allot more

Thanks for your help
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your problem actually is to convert a String into an int, correct?
 
Nick Le Boutillier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ilja

What I'm trying to do is get the value of the cookie i.e. something like

or

as an Int so I can use it as an argument in an IF statement

works to get the correct value from the cookie however I just want to get it as a variable that I can use.

Thanks for your help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!