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