• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the number of hits of a page

 
surya v
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai all,
In my research work i have to get the number of hits of a particular page. All the gurus try to suggest me how to get the hits of a page with/with out accessing to the logs. or suggest any products designed for this purpose.
thanx in advance
surya.
 
amit chaudhary
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply you can declare a variable(session) like this
<%! int counter = 1 ; %>
the modified value will be availbale to you till your server remains started ie value will be lost only if the the class files changes or server restarts.
 
ernest fakudze
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the very same problem too. it took me a long time to work it out because I always thought that a serialized bean could do this for me but alas or maybe i didn't know how to code it.
So I resorted to using a database. In my index.jsp page i have a small scriptlet which says sth. like:
update counterTable set count = count+1 where tableName = indeJSPPage
You then have to doisplay the value for the indexJSPOage column
This works because the database stores the infor. However, I think that this would be an inefficient approache if you wanted to track each page separately because you would have to have a table for each page.
 
Toyin Sogeke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You might want to use a singleton class
(i.e a class that can never have more than one
instance), which
can be easily called from anywhere within your
JSP pages.
You can design your singleton class to
1. have a static variable that can be incremented
2. have a static method that can write to a file
3. to have a static method that can read data from a file
Cheers
Originally posted by surya v:
Hai all,
In my research work i have to get the number of hits of a particular page. All the gurus try to suggest me how to get the hits of a page with/with out accessing to the logs. or suggest any products designed for this purpose.
thanx in advance
surya.

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why does the class need to be a singleton if all you're using are its static features?
Originally posted by Toyin Sogeke:
Hi,
You might want to use a singleton class
(i.e a class that can never have more than one
instance), which
can be easily called from anywhere within your
JSP pages.
You can design your singleton class to
1. have a static variable that can be incremented
2. have a static method that can write to a file
3. to have a static method that can read data from a file
Cheers

 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"surya v",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic