81,122
社区成员




<%!
int i=0;
%>
<%
Cookie[] mycookie = request.getCookies();
for(int n=0; n<mycookie.length; n++){
Cookie newcookie = mycookie[n];
if(!newcookie.getName().equals("ip")){
Cookie cookie = new Cookie("ip",request.getRemoteAddr());
response.addCookie(cookie);
}else{
i++;
break;
}
}
out.print(" 访问数 = " + i);
%>
Google Analytics 你可以看看。如果要做自己的访问统计系统,自己搭一个Piwik,参考这个开源实现
访问量的话,直接使用application对象不就好了,还与那个一个ip为一个访问数,这个没什么必要吧! <% Integer count = (Integer)application.getAttribute("count"); if(count != null){ count = 1 + count; }else{ count = 1; } application.setAttribute("count",count); %> 放到你需要的位置: <% Integer i = (Integer)application.getAttribute("count"); out.println("统计访问量:目前有 " + i +" 个人访问过本网站" ); %> 要是想把访问量加到数据库,自己写代码即可。
可以看下各大网站怎么样做访问统计的,不是你这个这样的做法,当然也不能直接在后台做。不能把robot的访问也算作用户的正常访问。
这个不能放在客户端来操作(也就是不能用cookie来记录),一般都是通过后台来记录的,然后还需要保存在数据库,而且这个不一定要现在每个IP只记录一次,如果要这样的话 也只能在数据库表里面加一个字段