Hi, well, you could also take the job out of the servlet at all (making you independent of the servlet's lifecycle) by developing a singleton class that (synchronized of course) takes log-requests from the servlet you mentioned. In order to not write to the DB everytime this singleton-logger simply loggs the requests in memory. To write it to the DB on a daily basis, just have a simple low-priority background-thread wake up everyday to take the counts from the logger (clearing it) and storing it into the DB.
hope that helps, Chris > I am buidling an online bookshop and would like to store how many people have visited the site and how many shopping cart has been created on a daily basis for sales analysis purpose. Something like, 200 people visited the site and 150 shopping cart were created on April 1, 150 people visited and 100 shopping cart were created on April 2, etc, etc. > > In the database, the primary key will be the date, and there will be two columns - one for the visit and the other for shopping cart. > > I've searched the archive and what I found from there did not really solve my problem. > > One way I can think of is to map a servlet to the root(where the index page is) and for each new session(not for each request for index page, because I don't want to include those accesses made by people who are already at the site) that gets created I increment the visit count in the database. Same thing goes for the shopping cart. However, I think this approach to write to database each time is costly in terms of db access. > > Another way which I think is more desirable is to store those counts in the servlet until the servlet gets destroyed. I guess I can write to database in the destroy method and get the latest count from database in the init method of the servlet. However, since what I want is the daily counts, not just the sum of everythings, how do I differentiate them and write yesterday's count to yesterday's column and write today's count to today's column, especially when I don't have control over when the servlet is destroyed? > > Hang on, how about this? I declare a vector(since I don't know how many Dates I will be storing until the servlet gets destroyed) as an instance variable, in the doGet method I instantiate a Date for each Session and compare it with the last Date element in the vector. If it's the same date, I increment the count that belongs to that Date, and if not, I add another Date element with new count. In the destroy method, I write what is in the vector to the database. In the init method, I get the last date from db with the count and store it in the vector......Would this work? Or is there an easier way? Am I making something that is so easy compliated? > > June > =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com
