有两种方法,一是自己写,二是用别人的
你要现成的,只需要在google里搜"免费计数器",就会有一堆的,一般是你注册一下相关信息(主要是你的网站链接),它就会给你生成一段代码,你把这段代码拷到你的网页里面就可以了.

解决方案 »

  1.   

    可以用javabean做,用它的application 属性~~
      

  2.   

    //File Name:Counter.java
    //Author:fancy
    //Date:2001.3.26
    //Note:use this JavaBean to Counter!
    package test;public class Counter
    {
    int Count=1;
    public void Counter()
    {
    }
    public void addCount()
    {
    Count++;
    }
    public int getCount()
    {
    return Count;
    }
    }**************************************************************<%--
    File Name:useCounter.jsp
    Author:fancy
    Date:2001.3.26
    Note:use javabean to say hello world!
    --%>
    <jsp:useBean id="counter" scope="application" class="test.Counter" />
    <br>
    你好你是第
    <%
    out.println(counter.getCount());
    counter.addCount();
    %>位访客
      

  3.   

    可以去连个网站流量统计的链接啊
    blog里就有的
      

  4.   

    可以用application,也可以用数据库或者直接写到文本文件保存就可以了!
      

  5.   

    <%@ page contentType="text/html; charset=GBK" %>
    <html>
    <head>
    <title>
    jsp1
    </title>
    </head>
    <body bgcolor="#ffffff">
    <%! int i=0; %>
    <% i++; %>
    <%="计数器"+i%>
    </body>
    </html>
      

  6.   

    index.jsp
    <%@ page contentType="text/html;charset=gb2312"%>
    <HTML>
    <HEAD>
    <BODY>
    <jsp:useBean class="zhao.SessionCounter"  id="sessionCounter" scope="application" />
    总计<jsp:getProperty name="sessionCounter" property="totalSessionCount" />
    当前在线<jsp:getProperty name="sessionCounter" property="currentSessionCount" />
    最大访问数量<jsp:getProperty name="sessionCounter" property="maxSessionCount" />
    </BODY>
    </HTML>
      

  7.   

    package zhao;import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;public class SessionCounter implements HttpSessionListener {
      private int totalSessionCount = 0;
      private int currentSessionCount = 0;
      private int maxSessionCount = 0;
      private ServletContext context = null;
      
      public void sessionCreated(HttpSessionEvent event) {
       System.out.println("Created!");
        totalSessionCount++;
        currentSessionCount++;
        if (currentSessionCount > maxSessionCount) {
          maxSessionCount = currentSessionCount;
        }
        if (context == null) {
          storeInServletContext(event);
        }
      }  public void sessionDestroyed(HttpSessionEvent event) {
       System.out.println("Destroyed!");
        currentSessionCount--;
      } 
      public int getTotalSessionCount() {
        return(totalSessionCount);
      }  
      
      public int getCurrentSessionCount() {
        return(currentSessionCount);
      }   public int getMaxSessionCount() {
        return(maxSessionCount);
      } 
      private void storeInServletContext(HttpSessionEvent event) {
        HttpSession session = event.getSession();
        context = session.getServletContext();
        context.setAttribute("sessionCounter", this);
      }
    }
    把这个编译一下就可以了
      

  8.   

    <%@ page contentType="text/html;charset=GB2312" %>
    <%@ page import="java.io.*" %>
    <HTML>
    <BODY BGCOLOR=cyan><FONT Size=1>
        <%! int number=0;     
         synchronized void countPeople()//计算访问次数的同步方法
            { 
              if(number==0)
                 { 
                   try{ 
                      FileInputStream in=new FileInputStream("count.txt");
                      DataInputStream dataIn=new DataInputStream(in);
                      number=dataIn.readInt();
                      number++;
                      in.close();
                      dataIn.close();
                     }
                      catch(FileNotFoundException e)
                       { number++;
                        try {FileOutputStream out=new FileOutputStream("count.txt");
                             DataOutputStream dataOut=new DataOutputStream(out);
                             dataOut.writeInt(number);
                             out.close();dataOut.close();
                           }
                         catch(IOException ee){}
                      }
                     catch(IOException ee)
                         {
                         }
                 }
              else
                 {number++;
                  try{
                      FileOutputStream out=new FileOutputStream("count.txt");
                      DataOutputStream dataOut=new DataOutputStream(out);
                      dataOut.writeInt(number);
                      out.close();dataOut.close();
                   }
                 catch(FileNotFoundException e){}
                 catch(IOException e){}
                }
         }
       %>
       <% 
          countPeople();
       %>
    <P><P>您是第
       <%=number%>
     个访问本站的客户。
    <BODY>
    <HTML>
      

  9.   

    用application啊
    比如
    application.setAttribute("counter","0");
    每进来一个就使application的变量加1
    然后用
    application.getAttribute("counter");获取啊
      

  10.   

    还是用Application最方便,但是不能持久,比如服务器重起,还是写在库里或文件里比较合适。
      

  11.   

    用Cookie 加Jsp吧
    Cookie防止按F5刷新,然后Jsp负责记录
    可以记录到数据文件或者数据库