• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hit Counter

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys
i am using a hit counter
i have created a bean with scope as application and am checking for "session.isNew()"
if this returns true then i increment the counter else i dont.
but the problem is that if i load my page count.jsp and then
go to suppose hotmail.com in the same browser then come back again to my page count.jsp then i want the counter to increment!but it doesnt....
could anyone plz help me with this
Now there is a second option which i am using
I am checking for the referer in the header which gives me the previous page.
i.e
request.getHeader("Referer")
gives me
null if i am putting the url in the browser
if i am coming from the same domain it gives me the following url
http://sameera:8080/examples/jsp/index.jsp
i am just checking that if the referrer is null or anything other than my machine( where server is present Tomcat 3.2.1) i increment the count but in this case
if i open a new browser and put the url
http://sameera:8080/examples/jsp/counter.jsp
it increments the counter but when isay refresh it again increments it which i dont want could any one gimme a solution
plzz
thanks in advance
i would surely post the code .. if the above explanation is confusing
plz help surely
Sam
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Session.isNew will only return true if the session is actually new. In you case (where you are visiting another site in the same browser and coming back) it will not be, because the session is still valid from the last visit to the site. If you open you page in another browser instance, you will probably find that the counter increases. If it doesn't we probably have a more fundamental problem, and you should post again.
Hope this helps
Sam
[ March 11, 2002: Message edited by: Sam Dalton ]
 
sameera kocharekar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sam
Well yes if i open a new browser then the count does increase
but it doesnt increases in the same window and yeah it is bcoz the session remains the same
but could u plz tell me a solution for this
like i want the count to increase when
1)Any of the pages of my site are being accessed.
2)if i open a browser open my page and then in same browser i go to hotmail then again i put the url of my site then in this condition also i want it to increase
# And i dont want it to increase when i load my page and refresh
Could u plz help me out
Thnks
sameera
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sameera kocharekar:
Hi Sam
Well yes if i open a new browser then the count does increase
but it doesnt increases in the same window and yeah it is bcoz the session remains the same
but could u plz tell me a solution for this
like i want the count to increase when
1)Any of the pages of my site are being accessed.
2)if i open a browser open my page and then in same browser i go to hotmail then again i put the url of my site then in this condition also i want it to increase
# And i dont want it to increase when i load my page and refresh
Could u plz help me out
Thnks
sameera



to full fill ur requirement i can suggest u a soln. but this soln only works if links to ur application pages doesn't exist any where out side ur application in whole world. according to me what u should do is just when ever any of teh page of ur application has been accessed by any one just check the HTTP referrer Header. if that is null then and only then increment ur hit counter else not.
with the help of above technic ur hit counter always increased by mentioned amount when ever any one directly enter url in the browsers address bar and never when some one click a link to jump to ur any of the JSP page.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers,
A question on the hit counter. (I posted this in the SCWCD forum) If Sameera is using a bean to store the hits - what happens when the Server is shut down and restarted. Where is the latest count value stored and how? I assume they want to keep track of a running total.
Regards,
Stephen Batsas
SCJP2
 
sameera kocharekar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there
well yeah i am checking for the referer in the header and if it is null then only i increase the count
But in this case if i load my page say
http://sameera:8080/examples/jsp/counter.jsp
(suppose this is the main page of my application)
and check for the referer which is null
and i incr the count
but now if i say refresh ot click the refresh button of the browser then for each refresh it adds 1 to the count.
could u plz tell me a solution for this refresh problem.
And yeah i am storing the hitcount in a file so even if i stop the server no probs..Thnaks
Sam
 
gautam shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ur hit counter algorithm should look like this.
if (referrer==null && session.isNew())
hitCounter++;
 
sameera kocharekar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys
i am back again
well thanks gautam
i had been doing the two things
i.e. checking for referer as null and checking for session.isNew() separately
now i am doing it together.Now my refresh problem has been solved.
But i still have a problem
Now take this condition
I open a browser and type the url
http://sameera:8080/examples/jsp/counter.jsp
and the hitcount increses by 1
now in the same browser i type
www.javaranch.com
i acces 1-2 pages concept is to go to another site and come back again to my page
ie now again i type
http://sameera:8080/examples/jsp/counter.jsp
now the referer is NULL but since the session.isNew() returns false the count does not increase
And i want this also to be considered as a hit
IS it possible?
I have tried really hard for this....
Plz do help me
Thanks
Sam
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sameer,
u are opening ur jsp page in the same browser.
so no question of session damage due to browser.
u are incrementing by checking session.isNew().
but this may give false because of the expiry of the session and in this case u will not be able to increment. and this is what is happening at ur side.
 
sameera kocharekar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well Well sameera
u have got me wrong i guess
See i get session.isNew() false bcoz i am in the same browser and not bcoz session expiry
What i want is that it should increase the count
I open a browser and type the url
http://sameera:8080/examples/jsp/counter.jsp
and the hitcount increses by 1
now in the same browser i type
www.javaranch.com
i acces 1-2 pages concept is to go to another site and come back again to my page
ie now again i type
http://sameera:8080/examples/jsp/counter.jsp
now the referer is NULL but since the session.isNew() returns false the count does not increase
And i want this also to be considered as a hit
Sam
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic