i am developing a hit counter in my web application to increase whenever a new user visits my website so that i will now the number of hits from different users so far. but the problem is that it is increasing even though it is the same ip address

How did you implement the counter? Are you handling the IP?

yes i am getting the ip by using

 <% out.println("Your IP address is: " + java.net.InetAddress.getLocalHost().getHostAddress());%> 

and the hit counter is implemented :

<%

                Integer applicationCount = (Integer) application.getAttribute("applicationCount");
                if (applicationCount == null) {
                    applicationCount = new Integer(1);
                } else {
                    applicationCount = new Integer(applicationCount.intValue() + 1);
                }

                application.setAttribute("applicationCount", applicationCount);
            %>

I'm mot a Java expert but it appears to me that the method you are using to maintaining a hit counter depends on your application server remaining uninterrupted. It you restart services, you will loose the count??

Since you want to incorporate handling the IP, i woukd tend to think that it may be a better solution to store the information in some type of data source, such as a data as a table.

@missc why trying to reinvent the wheel when there are tons of hit counters, beside they are obsolete and misleading. Secondly I want to cry any time I see anyone writing snipets in JSP...

how can i do it in other way ?

i think you have to use session varibale(or cookie variable) to store your site views.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.