Hello all,
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
N�����r��zf���%��lz��j���w(�����Ƞ���%#�51$Ţ�b��-�����b����ڽ�.��&�+an�r��IH�
LDDI0�D�J����^���,�rR?����^��������j�m���j�!�����ڲ�ܢo㲘����m�Xm�����ڲ�ܢo鮇nr�?��}���ia���
0z�^�������?㲟㲗ڪ;)��i��0�8.��(��ګ��u�c��m����#����'^��&