0

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

5
Contributors
7
Replies
9
Views
4 Years
Discussion Span
Last Post by jalpesh_007
1

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);
            %>
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.