• Post Reply Bookmark Topic Watch Topic
  • New Topic

Counting the number of hits on a link

 
Abhilash
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have a link in my website .. is it possible to keep a track of the number of hits on this link ..I am working in jsp .

My idea was to invoke a java method on clicking this link.Is it possible ?Is there any other way to do this .??

Please help me..
 
sudhir kamath
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

you can do certainly do it.put a variable in declaration tag some thing like
<! Int i=0 > and increment this variable in your scriplet code
regards,
sundeep
 
Abhilash
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Do u have any other way to do this ..Any idea .. do suggest ..i have to enter the value to database. Is it possible through the way you suggested? please give something like sample coding...
Thankyou
 
Indraneel A Das
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can do like this


in declarative tag <%! %> you are defining a member variable and a method.

in scriptlet tag <% %> you are calling the updateDB() method. This method will be invoked everytime the jsp page is requested.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Abhilash" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy. User names cannot be obviously fake and must constist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhilash,

An better alternative, IMHO, would be to create a filter that counts and logs the web site hits. If you are not familiar with filters, check out this link from ONJava.com for a decent tutorial on building filters.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree servlet filters are the way to go. I have such a filter that you can see in action, by visiting http://www.fdsapi.com and selecting the live demo. From here go to the jamon admin page to see page stats like hits, avg time, max time, min time and more. It does not persist the data to a db however.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!