2014年5月17日星期六

jsp articles ( posts ) access rate ( Reads ) function implementation issues


I'm thinking is : an ip access to a number , not duplicate , with Cookie achieve , and then determine the code below

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

how do I feel strange , after all, did not do , I hope to give a professional guide !

------ Solution ------------------------------------ --------
visits , it is not enough direct use of application objects , and also the one with the ip access to a number , this is nothing need it !
<%
Integer count = (Integer) application.getAttribute ("count");
if (count! = null) {
count = 1 + count;
} else {
count = 1;
}
application.setAttribute ("count", count);
%>

into the position you need:
<%
Integer i = (Integer) application.getAttribute ("count");
out.println (" Visits statistics : There are " + i + " personally visited the site " ) ;
%>


visits added to the database , if wanted , write your own code.
------ Solution ---------------------------------------- ----
Google Analytics you can see. If you do visit their statistical systems , he made himself a Piwik, refer to this open source implementation
------ Solution ---------------------- ----------------------
ask     
To record the real user access , resource access that users have to wait loaded before sending an http request access to records the user 's behavior , user behavior tracking website profound, free facie 51.la, google analytics, as well as specialized manufacturers webtrends and the like, are hair js http request to the background to a log file , and then analyze the log files.
------ For reference only -------------------------------------- -
have a field, and then not visited +1 , visited not operate.
------ For reference only -------------------------------------- -
nobody get over it? Still do not understand ?
------ For reference only -------------------------------------- -
this can not be operated on the client ( that is, can not be recorded with a cookie), usually through the background to record , and then stored in a database needed , and this need not be recorded only once per IP now , so if you want to add only one field
------ For reference only in a database table inside --------------------- ------------------
facie Know the major sites access statistics , and this is not your doing so , of course, can not be done directly in the background. The robot can also be regarded as a normal visit to access the user.
------ For reference only -------------------------------------- -
background behind me was a request to do to achieve first function to figure out , did not do so no idea
------ For reference only ------------ ---------------------------
ask
------ For reference only ---------------------------------------
not want to use this
- ----- For reference only ---------------------------------------
Thank

没有评论:

发表评论