• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how we can count no.of hits on a JSP page?

 
ramu ta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how we can count no.of hits on a JSP page?
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways, if you don't want to implement it your self, you can use some analytics service like, "google analytics" or statcounter. With this services you will get many more information like where the visitors came from, search engine keywords etc..

If you want to implement a hit counter your self.. see this JSP Life Cycle example. It explains exactly same thing, A request counter.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! I hope that article is very old because it uses a lot of bad practices!
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The article is for absolute newbies, who doesn't have even basic idea's about JSP.. The article doesn't intend to explain how to write a good JSP page, the purpose is to let them understand the life cycle, and if ever they want, how they can declare variables, functions inside JSP. I know it's not a good practice to have jsp declare variables, use scriptlets and jspInit. But I believe, Still newcomers should know about those parts of JSP.
 
ramu ta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I disagree. Exposing newcomers to poor practices just instills them as a bad habit that needs to be broken later. Any article on JSP written after 2002 should pretend that scriptlets and scriptlet expressions do not even exist, or, at best, mention them in passing as something that needs to be avoided at all costs.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ramu ta wrote:thank you

See? Now ramu is likely to go ahead and implement this using scriptlets and scriptlet declarations and that is a poor practice that he will have to unlearn later.

I'd use a filter to count hits and keep the goop off of the pages.
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read at the end of the article, there's a note about the same thing.

To Ramu : As Bear said, its really not a good practice to implement it this way, It's just for absolute beginners to see log messages when a jsp is initialized, destroyed and when jsp receives a request, it's just an example and not some thing that you should copy to your production code. As Bear said, you can write a filter that will intercept all request to your jsp page and implement the counter there.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too little, too late, in my opinion. Let's hope people take heed of that.
 
ramu ta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya, i knew the filter concept. i asked this question to know the otherway to count hits without using filter
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ramu ta wrote:ya, i knew the filter concept. i asked this question to know the otherway to count hits without using filter

If you just want to try out, it's fine to implement the counter yourself, either filter or other way. But if you really want the page analytics, I would suggest get google analytics (If you must not have to).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On that we can very much agree. The best place to count the hits is outside the page!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic