想统计一下网站的访问量,注册会员等等。这个功能怎么做,谁有代码?看看,谢谢

解决方案 »

  1.   

    记录网站访问量的例子很多啊 http://topic.csdn.net/t/20041020/15/3474283.html
    这里头 把 访问量写在文件里 数据库 n多 其实无外乎就是 把访问量写在一个变量里 保存在任何地方 仔细看一下吧 加油
      

  2.   

    1.用session超时,session为null就表示下线了  
     
    2.也可以采用数据库中设置  临时表  来处理  
    一个用户登陆时向表中插进一条记录,用户离开时候删除该记录  
    如想统计在线人数,简单地执行  
    select  count(*)  from  table...  即可  
     
    3.application对象中可以记住现在的人数,application的生命周期和服务器的生命周期一样长。  
     
    4.还有一种方法要用到一个文件global.jsa  ,方法是(在JSP中)是sessionDestroy(),其中它是以session对象为参数的。还有要把global.jsa文件必须房子和JSP程序相同的文件目录内才行。  
     
    5.网页自动刷新的代码是:  
    在文件头部加上  
    <meta  http-equiv="refresh"  content="15">  
    刷新间隔时间是15秒  
     
     
    6.在session中加入监听类,类的示例代码如下:  
    onLineUser.java  
    import  javax.servlet.http.*;  
    import  javax.servlet.*;  
    import  java.util.*;  
     
    public  class  onLineUser  implements  HttpSessionBindingListener  {  
               public  onLineUser(){  
           }  
     
           private  Vector  users=new  Vector();  
           public  int  getCount(){  
                   users.trimToSize();  
                   return  users.capacity();  
           }  
           public  boolean  existUser(String  userName){  
                   users.trimToSize();  
                   boolean  existUser=false;  
                   for  (int  i=0;i<users.capacity();i++  )  
                   {  
                           if  (userName.equals((String)users.get(i)))  
                           {  
                                   existUser=true;  
                                   break;  
                           }  
                   }  
                   return  existUser;  
           }  
     
           public  boolean  deleteUser(String  userName)  {  
                   users.trimToSize();  
                   if(existUser(userName)){  
                           int  currUserIndex=-1;  
                           for(int  i=0;i<users.capacity();i++){  
                                   if(userName.equals((String)users.get(i))){  
                                           currUserIndex=i;  
                                           break;  
                                   }  
                           }  
                           if  (currUserIndex!=-1){  
                                   users.remove(currUserIndex);  
                                   users.trimToSize();  
                                   return  true;  
                           }  
                   }  
                   return  false;  
           }  
     
           public  Vector  getOnLineUser()  
           {  
                   return  users;  
           }  
               public  void  valueBound(HttpSessionBindingEvent  e)  {  
                   users.trimToSize();  
                   if(!existUser(e.getName())){  
                           users.add(e.getName());  
                           System.out.print(e.getName()+"\t      登入到系统\t"+(new  Date()));  
                           System.out.println("            在线用户数为:"+getCount());  
                   }else  
                           System.out.println(e.getName()+"已经存在");  
               }  
     
               public  void  valueUnbound(HttpSessionBindingEvent  e)  {  
                   users.trimToSize();  
                   String  userName=e.getName();  
                   deleteUser(userName);  
                   System.out.print(userName+"\t      退出系统\t"+(new  Date()));  
                   System.out.println("            在线用户数为:"+getCount());  
               }  
    }  
    <%@  page  contentType="text/html;charset=gb2312"  %>    
    <%@  page  import="java.util.*"  %>    
    <jsp:useBean  id="onlineuser"  class="temp.jb.onLineUser"  scope="application"/>  
    <html>    
    <head>    
    </head>  
    <body  onUnload="postMessage()">    
    <center>    
         <p><h1>登陆成功,欢迎访问</h1></p>  
    </center>  
    <%      session  =  request.getSession(false);  %>    
    <%    
           String  username=request.getParameter("username");  
           if  (onlineuser.existUser(username)){  
                   out.println("用户<font  color=red>"+username+"</font>已经登陆!");  
           }else{  
                 session.setMaxInactiveInterval(50);  //Sesion有效时长,以秒为单位  
                   session.setAttribute(username,onlineuser);    
                   out.println("欢迎新用户:<font  color=red>"+username+"</font>登陆到系统!");  
           }  
           out.println("<br>当前在线用户人数:<font  color=red>"+onlineuser.getCount()+"</font><br>");  
           String  ip  =  request.getRemoteAddr();  
           out.println("<br>IP:<font  color=red>"+ip+"</font><br>");  
           Vector  vt=onlineuser.getOnLineUser();  
           Enumeration  e  =  vt.elements();  
           out.println("在线用户列表");  
           out.println("<table  border=1>");  
           out.println("<tr><td>用户名</td></tr>");  
               while(e.hasMoreElements()){  
                   out.println("<tr><td>");  
                   out.println((String)e.nextElement()+"<br>");  
                   out.println("</td></tr>");  
           }  
           out.println("</table>");  
                 
    %>    
    <center>    
         <p>  </p>  
         [<a  href="javascript:window.close()">关闭窗口</a>]  
    <%  
           out.println("<p><a  href='logout.jsp?username="+username+"'>退出系统</a></p>");  
    %>  
    </center>    
    <Script>  
               function  postMessage(){                                
                               <%onlineuser.deleteUser(request.getParameter("username"));%>  
         }  
    </Script>  
    </body>    
    </html> 
      

  3.   

    <%@ page contentType="text/html;charset=gb2312" language="java"%> 
    <%! 
    synchronized void countPeople() 

      ServletContext application=getServletContext(); 
      Integer number=(Integer)application.getAttribute("Count"); 
      if(number==null){ 
      number=new Integer(1); 
      application.setAttribute("Count",number); 
    }else{ 
      number=new Integer(number.intValue()+1); 
      application.setAttribute("Count",number); 
    }} %> 
    <% 
    if(session.isNew()) 
    {countPeople(); 
    Integer myNumber=(Integer)application.getAttribute("Count"); 
    session.setAttribute("MyCount",myNumber); 

    %><h3 align="center">您是第<font color="red"><% 
    int a; 
    if(session.getAttribute("MyCount")!=null) 
    {a=((Integer)session.getAttribute("MyCount")).intValue();} 
    else 
    {a=1;} 
      %><%=a %></font>个访问本站的客户。</h3>  
      

  4.   

    可以用Application来做此对象的作用域是全局的当然当你关闭服务器的时候 要让这些数据持久化
      

  5.   

    这些不用自己做,直接到 cnzz 上注册一个就可以了,他的统计会比你自己做的详细的多,而且免费。