I need to count Page hit for every page. Every page should show the number of times the said page has been accessed. I need to show message like "This is 20th visit to this page"
I have searched the code ranch forum and googled and have found below solutions.
There are multiple approaches:
a: Use DB to store and return every page visit
b. Use a custom tag to implement the page hit counter. This approach has below issues
(i)The issue is that the counter would be lost when the app will be restarted. Thus would need to persist the counter for every page and re-initialize counter again for every page. Any idea on how can I get a handle to all pages' hit counter in a ServletContextListener(is there a API support for this)
(ii) This may not work correctly in a clustered application and thus there will be multiple instances of same page and thus different counts. I am looking for any suggestions to resolve this.
I feel solution a) might be a lot of over engineering for a little stuff. But I would like to hear what other people have to say and how they have handled it in their applications.
May be you can use a file which just contains the count and everytime you can increment the count in the doPost/doGet method exits, if you really do not want to use the DB
But again, as the unwritten rule for any software problem is there are n number of ways to solve it.