Saturday 19 September 2015

How to set visitor counter in your website its coding

If you want to on your website visitor counter then it means count online user which access your websites at current time in servlet. you are set in your website very easy you can see my example below.






## For Example



I am provide for you some codes just copy and paste where you want to set your visitor counter this is very useful for you.



 ServletContext ctx = getServletContext();
           Integer count = (Integer)ctx.getAttribute("count");
           if(count == null)
           {
               count = new Integer(0);
           }
           count = new Integer(count.intValue()+1);
           ctx.setAttribute("count", count);
           out.println("Visitor count: " +count+"");




Note: If you are create .jsp page then this code is valid or if you are create .java class then you are just change some code. replace out.println("Visitor count:" +count+""); into System.out.println("Visitor count: " +count+"");



Note : If you have any problem then reply me.

No comments:

Post a Comment