To build an image-based counter, write a servlet -- let's say /myapp/counter -- that works as follows:
public void doGet(...) {
incrementCount();
Image i = getImage();
writeImage(response);
}
Of course, you still have to write the incrementCount, getImage, and writeImage methods :-) In your client pages, output the following HTML:
<IMG SRC="/myapp/counter">
and each client request will increment the count and display the image in a single shot.
(This simple architecture would have been possible for text too, if only Marc Andreesen had simply implemented client-side include in Netscape, instead of wasting all his time on tables and frames, which totally suck. Oh well, maybe next life.) However, this technique is not always accurate, since it can count reloads, if the same user goes back to the home page. Also, you may end up counting hits to sub-pages too. Adding a parameter, as in IMG SRC="/myapp/counter?page=home" may help distinguish these case.