Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Website Hit Counter Jsp and Bean Based.

 
vinay abhishek
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have developed a Jsp page which tracks every hit, It increments the count and stores it in the Database(MySql).
Now I would like to make the code Generic by putting the entire logic in the backing bean and provide a reference of the bean for every JSP page whose count I would like to monitor.
Here is the code.


Now How do I get started with the idea

 
Stefan Evans
Bartender
Posts: 1712
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it you are "counting" here?

The number of pages one user visits in your app?
You are inserting a new record at every session. I would check your database table to see how many rows it has right now. My guess would be it has several rows, all with the same value :-)

Suggestions
- Database queries/code are expensive. At the least use a pooled database connection rather than creating a new one each time.
- Shifting this logic into a java class is good
- I would suggest you take a look at using a Servlet Filter.
- Work out what you are counting (counts for each page? for each user? ) and store that information as well.

 
vinay abhishek
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this way I was able to monitor the count based on a session and add it into the database.


I plan to use connection pool and java persistence API to have the back up for the count. That is fine.
But when I try to Generalize the code by building an enterprise java bean I am badly struck with it.
For example I try to monitor the hit rate of a JSF page. I annotate the give a Managed Bean annotation to the backing bean.
How do I call the counting logic that is in the bean class, in my JSF page? I assume that if I can pass an invisible or a secret value from the JSF to the count logic in the bean, it would count the number times page was hit. Is the a correct idea? If so how do I get Started? Help needed.
What if I want to check the hit rate for a plain HTML page? This is also a unsolved.
 
vinay abhishek
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here when I say hit rate, I mean the number of times a page is accessed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic