File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes counter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "counter" Watch "counter" New topic


harivarma mudunuru

Joined: Sep 07, 2000
Posts: 8
How can I know how many visitors are currently visiting my site using sevlets?
Sid Sharama

Joined: Feb 06, 2005
Posts: 11
have an integer (say counter = 0) declared in your Servlet class.
in doGet() or doPost() increment the counter.
and while sending the response
out.println("so far" + count + "visits were made to this site");
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Hmm. That will tell you how many have visited so far, but not how many are 'visiting' now. The latter is actually very difficult to figure out.
Say someone requests a page from your site. Do you assume they are actually reading it? A server can't tell if someone types in another URL to their browser to get a page frmo another site. A browser can't tell if a user walks away from the computer, or does something else completely. Is that what you are trying to find out?

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: counter
It's not a secret anymore!