aspose file tools*
The moose likes Servlets and the fly likes How to get the number of hits of a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get the number of hits of a page" Watch "How to get the number of hits of a page" New topic
Author

How to get the number of hits of a page

surya v
Greenhorn

Joined: Oct 08, 2001
Posts: 1
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

Joined: Oct 10, 2001
Posts: 2
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

Joined: Aug 27, 2001
Posts: 216
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.


In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer
Toyin Sogeke
Greenhorn

Joined: Oct 08, 2001
Posts: 14
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.


homeboy
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jan 07, 1999
Posts: 6920
"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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the number of hits of a page