Have a question? ask www.kenlet.com
Home  |  FAQ  |  About  |  Contact  |  View Source   
 
SEARCH:
 
BROWSE:
    My Hood
Edit My Info
View Events
Read Tutorials
Training Modules
View Presentations
Download Tools
Scan News
Get Jobs
Message Forums
School Forums
Member Directory
   
CONTRIBUTE:
    Sign me up!
Post an Event
Submit Tutorials
Upload Tools
Link News
Post Jobs
   
   
Home >  Tools >  Website Components >  Simple JSP/JavaBean Website Hitcounter
Add to MyHood
Simple JSP/JavaBean Website Hitcounter
Stats
  Rating: 4 out of 5 by 2 users
  Submitted: 05/01/02
Jesse Martin (Jess3647@ufl.edu)

Download This Tool: 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/


Return to Browsing Tools

Email this Tool to a Friend

Rate this Content:  
low quality  1 2 3 4 5  high quality



Reader's Comments Post a Comment
 
Hey Guys... there is one last thing that I forgot to note. The first line in HitCounter.java says:

package jesse3647.servlet;

Of course, this should be changed to path of where your compiled HitCounter.class file is located. In this example, the file is located in the jesse3647/servlet directory. It is very important to change this to what it should be, or you will get a HTTP 500 internal server error (Page not found).

Sorry for the innconvence... that's JSP for you!

-- Jesse Martin , May 02, 2002
 

Copyright © 2001 DevHood® All Rights Reserved