|
Home > Tools > Website Components > Simple JSP/JavaBean Website Hitcounter
|
|
|
Simple JSP/JavaBean Website Hitcounter
|
|
Rating: 4 out of 5 by 2 users
|
|
Submitted: 05/01/02
|
|
|
|
Jesse Martin
(Jess3647@ufl.edu)
|
|
|
Download This Tool:
|
hitcounter.zip
|
Disclaimer
|
|
|
This is a very simple hitcounter that can be used on a JSP website. IT DOESN'T USE SQL OR ANY KIND OF SPECIAL DATABASE. Instead, it simply stores/reads an integer value into a file and determines extensions of the numbers (ie: 100th, 21st, 33rd...). The basic purpose of this tool is to demonstrate JavaBeans and JSP.
HOW TO USE: The first thing I should point out is that this zip file contains two files -- HitCounter.java and template.out. HitCounter.java is the javabean. It contains all of the source you need to run the tool. The other file, template.out, is the file where the actual data is stored. This file is a template, meaning you can (and should) change the name of the file to something that better suits you (IE: change it to the name of the webpage that you are doing the hitcounting on).
To run the tool, you must upload it to your JSP server and compile it. After that, just add the below code into your JSP page:
<jsp:useBean id="counter" class="PATH.TO.JAVABEAN"> <%out.print(counter.getHitCounter("PATH TO DATA FILE"));%> </jsp:useBean>
Be sure to change the appropriate code (stuff all caps) to what you need it to be. A good example of a way this could be done is as followed:
<jsp:useBean id="counter" class="jesse3647.servlet.HitCounter"> <%out.print(counter.getHitCounter("counter/index.out"));%> </jsp:useBean>
That's it!! If you would like to see a working sample of this code, check out my website at http://www.mycgiserver.com/~jesse3647/
|
|
|