Re: counts the number of hit on a website containing many JSPs
Garg wrote:
I am having a scenario in which I am having a full public website,
which won't require any login. I want to count the number of hits to
that website.
like :
1.
count = 0
if i [sic] hit http://www.abc.com/xyz1.jsp then count should become 1
and if i [sic] hit on http://www.abc.com/xyz2.jsp then count should become 2
(I am writing these urls in the address bar and clicking enter)
2.
count=0
if I hit http://www.abc.com/xyz1.jsp then count should become 1 and
then if I navigate tohttp://www.abc.com/xyz2.jspby clicking any
hyper link on xyz1.jsp file the count should remain 1
I this i [sic] don't want to put the code in every JSP. I need a common
place.
So please tell me where I should put my code and variable count.
If your application has an architecture that allows users to directly
type in a screen and bypass the welcome page, you will have great
difficulty with this.
The best-designed web applications have a single point of entry and
all navigation within the site is via links. actually, via active
controls like "submit" buttons that are under the complete control of
the application. With such a correct design, you can easily decide
what to count because the application controls all navigation.
If you insist on allowing people to access pages directly, make all
intra-application navigation via active buttons rather than links.
Then simply make sure that intra-application navigation includes a
"don't count" token in the submission, and if that token is absent
then count the hit.
You can include headers and footers for screens in web applications
via JSP groups in the web.xml. Alternatively, you can use the <
%@include ...> mechanism in each JSP.
Your counting question goes away entirely in a correctly-architected
application that controls its own navigation. If you use what I'll
kindly call a more chaotic architecture then the problem becomes
harder. If you use anchor links to navigate within the app, then I
don't think there really is a way to do what you want.
The Model-View-Controller architecture pattern will help you.
--
Lew