Here is something completely off the top of my head. I thought this would work at first, but now I realize it won't at all.
My first thought was: Use < %! tags. This is a class wide variable. So that means it is outside the service method of the compiled
JSP. So... You would have something like:
But this only counts page 'views', not a 'current number of people viewing the page'.
Second idea:
If you wrote a servlet called "PageRequestor"
Every single link (EVERY LINK) that you would ever have on your site would always use the PageRequestor, so that your site URLS would look like:
http://localhost:8080/webContext/PageRequestor?page=page1.jsp Inside the servlet, there would be (an array? / a Vector?) of all the pages on your site. You would then bump up the count on that page by one.
But whoops... how do you subtract pages? You would have to look at the incoming request, and perhaps you could use a 'referrer' (parameter/field?). It's used by websites to tell them from where their visitors came. (what was the last page you were just on?). So maybe you could use that to subtract... If someone was 'just on' page1.jsp, then you'd subtract one from that page.
The only problem is some security-conscious folks have software that blocks this information from your servlet. So it couldn't be used reliably.
So the final story is: I'm really not sure how to do it without sessions. The web is stateless. If you want to add and subtract a running count of "how many people are here right now?", this is a good example of maintaining state... which the web just doesn't do.