• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the number of hits of a page

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic