This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Punit Jain wrote:hello i need to store number of visitors in cookie
No you don't. Cookies are specific to one specific browser for one specific user. That means that if I visit your site in Firefox, that cookie may have a different value from when I visit your site in Chrome. If you then visit your own site in Chrome you may get a different value again. If the visits are only stored in cookies then my Chrome browsing session isn't aware that I already visited your site with Firefox, and it's definitely not aware of your visits.
Number of visitors are a measurement that belongs to the server, not the client. That means you must use server side techniques for storing them, and that rules out cookies. In memory you can use servlet context attributes, for persistence you need to use a database, a physical file or something else like that.
ya that i know, but this is just like my assignment, and i m just doing this but i m not going to implement it anywhere??
so i only need to test here, how to store visitors into cookies, and write now i am running my website on local..
so this is only mt learning activity..
So you basically only need to convert an int to a String? Check out some of the static methods of Integer and String, there are a few that can help you out.
Joined: Aug 20, 2011
Rob Spoor wrote:So you basically only need to convert an int to a String? Check out some of the static methods of Integer and String, there are a few that can help you out.
okay it's working for me now, thank you...
but one problem still here is at the first time it showing me Name and the second refresh, nickName, but after that my if else is not working i mean counter are increasing after each refresh but always showing nickName..
Punit Jain wrote:one more thing i want to know here,as i initialized variable count in class
so is it thread-safe ??
It will be when you move that line into the doPost method.
yes than it will be, but if i move the line into doPost, than it will not increment my counter, (ie. it will initialized each time)..?
The counter's initial value should come from the cookie. If there is no value in the cookie (i.e. first visit, or user deleted or blocked cookies) then it's initial value can be set to 0. Then you increment it and update the cookie with the new value.
Also, aggregate information such as "Number Of visitors using cookies is" and "You are Visitor number" cannot be implemented by simply and only using cookies. This has been explained already in your how to count number of visitors thread. You have to keep track of such information on the server side.
Joined: Aug 20, 2011
yap i know, i m doing this only for my learning exercise..