Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

no. of hits in a web page  RSS feed

 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers
I'm doing a project in JSP. I want to get the totol no. of times the page was opened. when we type www.x.com it has to show the total no. of times visited.

Which is the possible way to do that..

Please help me rachers
Thanks in advance

regardz
ARavind
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to do it.

There are also many ways to interpret "number of hits".
Do you want the number to increment if the same use reloads the page or leaves the page but comes back within the same session?

Are you already using a relational database with your app?
If not, you'll need to decide whether this feature warrants setting one up or whether it would be easier to write the count to a file.
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ben Souther,
When the same user refreshes the page.. i want to increment the counter.
How can i do that..

Please reply me as soon as possible

Thanks and regardz
Aravind
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
There are many ways to do it.

There are also many ways to interpret "number of hits".
Do you want the number to increment if the same use reloads the page or leaves the page but comes back within the same session?

Are you already using a relational database with your app?
If not, you'll need to decide whether this feature warrants setting one up or whether it would be easier to write the count to a file.
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben Souther ,
I'm not using any RDBMS.. It is just a static website with 5 pages..
when ever the enduser opens the webpage index.jsp.. it has to show.. the number of hits= #### something like that..

Once if he closes and opens it again.. means
it has to show.
#### + 1 like wise

Please reply me how to do that..

Thanks in advance and regardz
Aravind
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, it's considered a bad idea to put any business logic, database, or filesystem access in a JSP.

For a task like this, I would use a custom tag.

If you just want a hit counter and you want it quickly, I would look around to see if just such a tag already exists. Judging from this Google search, I'd say there are lots of them:
http://www.google.com/search?hl=en&lr=&q=JSP+HIT+COUNTER+TAG&btnG=Search

If you want to do this yourself, as a learning excersise, I would recommend first, writing a small standalone java app that reads and writes to a file.
Once you get that working, read up on JSP Custom tags. Then, either move that the logic from your standalone class into your tag or, make your standalone class comply with the rules for Javabeans and call that class from your tag.
[ September 28, 2006: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!