Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > counts the number of hit on a website containing many JSPs

Reply
Thread Tools

counts the number of hit on a website containing many JSPs

 
 
Garg
Guest
Posts: n/a
 
      06-30-2008
Hi All,

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 hit http://www.abc.com/xyz1.jsp then count should become 1
and if i 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 to http://www.abc.com/xyz2.jsp by clicking any
hyper link on xyz1.jsp file the count should remain 1

I this i 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.

Thanks in advance,
Tarun
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      06-30-2008
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
 
Reply With Quote
 
 
 
 
Garg
Guest
Posts: n/a
 
      06-30-2008
> 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.


basically this is a simple website without any authentication and
using JSP/Servlets. And why this problem happen is because sometimes
user copy the url and send it to anyone and that guy clicks that url
and the page is open. But in this condition i am not able to increment
the count.

tarun
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      06-30-2008
In article
<(E-Mail Removed)>,
Garg <(E-Mail Removed)> wrote:

> > 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.

>
> basically this is a simple website without any authentication and
> using JSP/Servlets. And why this problem happen is because sometimes
> user copy the url and send it to anyone and that guy clicks that url
> and the page is open. But in this condition i am not able to increment
> the count.


Tarun: Lew has proposed several excellent of ways to control access to
your web application that would preclude this problem. You cannot
"control access" and "not control access" at the same time.

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
 
Reply With Quote
 
Abhijat Vatsyayan
Guest
Posts: n/a
 
      06-30-2008
Garg wrote:
> Hi All,
>
> 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 hit http://www.abc.com/xyz1.jsp then count should become 1
> and if i 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 to http://www.abc.com/xyz2.jsp by clicking any
> hyper link on xyz1.jsp file the count should remain 1
>
> I this i 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.
>
> Thanks in advance,
> Tarun

If you are willing to create a session for all users irrespective of
which URL they access, filters might help you. You can use a filter to
intercept all requests (or only the ones you want included in the
count), look at the session and figure out if this is a new user.
 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      07-01-2008
Garg wrote:
> Hi All,
>
> 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.


You don't say what you want to do with that count. I'll assume you want
to produce a report for your own study rather than present it to the
user (e.g. at the bottom of every web-page).


> like :
> 1.
> count = 0
> if i hit http://www.abc.com/xyz1.jsp then count should become 1
> and if i 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 to http://www.abc.com/xyz2.jsp by clicking any
> hyper link on xyz1.jsp file the count should remain 1
>
> I this i 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.


I'd post-process the web-server's access log.

--
RGB
 
Reply With Quote
 
GArlington
Guest
Posts: n/a
 
      07-01-2008
On Jun 30, 6:33 pm, Garg <(E-Mail Removed)> wrote:
> Hi All,
>
> 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 hithttp://www.abc.com/xyz1.jspthen count should become 1
> and if i hit onhttp://www.abc.com/xyz2.jspthen count should become 2
> (I am writing these urls in the address bar and clicking enter)
>
> 2.
> count=0
> if I hithttp://www.abc.com/xyz1.jspthen 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 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.
>
> Thanks in advance,
> Tarun


I would suggest to allocate the session per user (as suggested by
"Abhijat Vatsyayan")
and then count for each request per session checking cgi var
"HTTP_REFERER", when the user follows the link this var will contain
the page where they come from, when the user types the address this
var will be empty...
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      07-01-2008
In article <(E-Mail Removed)>,
Lew <(E-Mail Removed)> wrote:

> Garg wrote:
> >> basically this is a simple website without any authentication and
> >> using JSP/Servlets. And why this problem happen is because sometimes
> >> user copy the url and send it to anyone and that guy clicks that url
> >> and the page is open. But in this condition i [sic] am not able to
> >> increment
> >> the count.

>
> John B. Matthews wrote:
> > Tarun: Lew has proposed several excellent of ways to control access to
> > your web application that would preclude this problem. You cannot
> > "control access" and "not control access" at the same time.

>
> The suggestions I gave were in the context of a web application written
> without any authentication and using JSPs and servlets. Go back and review
> them in light of that fact.


Reviewing...

Tarun: Lew is correct. It might have been clearer had I said, "control
navigation" rather than "control access", but the point is the same:
Even without authentication or for a deep link, you can control
navigation. Simply forward the request to your welcome page for a new
session. I understand you are in a hurry, but you must study the answers
you receive. Here are an excellent book and tutorial on the topic:

<http://pdf.coreservlets.com/>
<http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/>

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
 
Reply With Quote
 
shakah
Guest
Posts: n/a
 
      07-01-2008
On Jun 30, 2:30*pm, Lew <(E-Mail Removed)> wrote:

[..snip...]

> 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.


[..snip...]

It's tough to categorize an approach which doesn't use hyperlinks
in a web application as "best-designed". It sounds like you're
bringing a desktop application mentality to web-based app design.
 
Reply With Quote
 
Garg
Guest
Posts: n/a
 
      07-01-2008

> Tarun: Lew is correct. It might have been clearer had I said, "control
> navigation" rather than "control access", but the point is the same:
> Even without authentication or for a deep link, you can control
> navigation. Simply forward the request to your welcome page for a new
> session.


Thanks John for your input. But i can't implement this because it
needs a lot of code change.

servlet life cycle says that init or service method of the servlet
will be called whenever you call for the servlet. Can't i do something
so i can put a layer before init or service method and that layer will
increment the count or check any necessary thing like authentication
if i need to do that.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Libraries in a WAR containing JSPs? Lee Crawford Java 1 12-30-2006 04:09 AM
Can't hit the site by name but I can hit by IP CK ASP .Net 9 10-19-2006 08:01 PM
ACLs not showing hit counts on active UDP SYSLOG DigitalVinyl Cisco 7 04-08-2005 02:08 PM
Free website hit counter Martin R. Howell Computer Support 4 12-16-2004 12:51 AM
How to count how many times a submit button is hit Mogga HTML 3 11-18-2003 09:43 PM



Advertisments