Getting Visitor Number in jsp

Dear all,

We want to display visitor number. how can we do it in jsp?

Thanks.

you’re going to have to provide a bit more information than you have to be able to get help. Are you asking about a simple hit counter? a tracker? or what

Dear dc dalton,

We just want to display a simple hit counter whenever the user visits the webpage.

Thanks.

Do a Google search on web counter or visit statistics or something similar. There are many sites from which you can download the code to implement a web counter in your home page. Copy and paste the code to where you want it in your home page, and Bob’s your uncle. Here is an example: http://members.optusnet.com.au/~malan2000

you could also make your own hit counter fairly easily if that is what you really want to do. You just need a way to store the data. It could even be a simple .txt file that you write to and then read from. You can look in the java.io.* section of the API.

Or you could put it into your database if you are using JDBC and then just use queries to store and retrieve the data.

One thing you should decide is what counts as a hit. Is it every time the user reloads the page? or is there only one hit per session? in the latter case, you will need to check session ID.

Nina

Nina,
Could you elaborate a little on making my own hit counter? I would like to track my visitors and where they are clicking in from but do not want a visible counter on my pages.
Thanks

are you delivering the pages with jsp? are you using a database like MySQL?

Following steps might help you in that

  1. create one common jsp file e.d. counter.jsp
  2. include this file in all your JSP files. THis will execute as any of your JSP file gets executed. or u can add this page in only those file which u want to count
  3. create one txt file on ur server
  4. in jsp get the value from the txt
  5. if the value is blank make it 1 and store back in the txt file
  6. if value present, increment it by 1 and store the value back in the txt file
  7. in the count.jsp show the value of the txt file.