This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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 :-)
- 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.
Joined: Nov 23, 2012
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.
Joined: Nov 23, 2012
Here when I say hit rate, I mean the number of times a page is accessed.