http://blog.csdn.net/gjd111686/archive/2004/07/16/42852.aspx
<script>
n0=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x5,0x5,0x5,0xF}";
n1=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0x4,0x4,0x4,0x4,0x4}";
n2=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x4,0xF,0x1,0xF}";
n3=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x4,0xF,0x4,0xF}";
n4=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0x5,0x5,0xF,0x4,0x4}";
n5=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x1,0xF,0x4,0xF}";
n6=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x1,0xF,0x5,0xF}";
n7=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x4,0x4,0x4,0x4}";
n8=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x5,0xF,0x5,0xF}";
n9=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0xF,0x5,0xF,0x4,0xF}";
nD=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0x0,0x0,0xF,0x0,0x0}";
nS=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0x0,0x0,0x0,0x0,0x0}";
nT=
"#define t_width 3\n"
+"#define t_height 5\n"
+"static char t_bits[]={0x0,0xF,0x0,0xF,0x0}";
function setImg()
{
 var now=new Date();
 var month=now.getMonth()+1;
 var strNow=strFormat(""+now.getYear(),4)+"D"+strFormat(""+month,2)+"D"+strFormat(""+now.getDate(),2)+"S"+strFormat(""+now.getHours(),2)+"T"+strFormat(""+now.getMinutes(),2)+"T"+strFormat(""+now.getSeconds(),2)+"T"+strFormat(""+now.getMilliseconds(),3);
 ClockID.innerHTML="";
 var vImg="";
 for(iInde=0;iIndex<strNow.length;iIndex++)
 {
  vImg=vImg+"<img src=\"javascript:n"+strNow.substr(iIndex,1)+";\" width=\"9\" height=\"15\">\n";
  ClockID.innerHTML=vImg;
 }
}
function strFormat(str,iLen)
{
 if(str.length<iLen)
 {
  for(iIndex=0;iIndex<iLen-str.length;iIndex++)
  {
   str="0"+str;
  }
  return str;
 }
 else
 {return str;}
}
setInterval("setImg()",2000);
</script>
<center>
<div id="ClockID">
</div>
</center>

解决方案 »

  1.   

    <script>
    function window.onbeforeunload()
    {
    if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
    {
    window.event.returnValue="确定要退出本页吗?";
    }else
    {
    window.confirm("刷新");
    return false;
    }
    }
    </script>
      

  2.   

    <%@ page language="java" contentType="text/html;charset=gb2312"%>
    <%
    int count = ....; // 从数据库或文本中取得当前计数
    String hasCount = session.getAttribute("hasCount");
    if( hasCount == null ) {
      count++;
      session.setAttribute("hasCount", "yes");
      //把新的计数更新到数据库或文件
    }
    out.println(count);
    %>
    要用图片替换数字,只需要改最后的一部分
    在images文件夹下放count0.gif,count1.gif,count2.gif,count2.gif...count9.gif,
    把out.println(count);改成:
    String countS = String.valueOf(count);
    char[] c = countS.toCharArray();
    for(int i = 0; i < c.length; i++){
    %>
    <img src="images/count<%=c[i]%>.gif">
    <%}%>这样就可以了,上面没有测试,临时写的一点.你再自己补充测试一下.
      

  3.   

    <jsp:useBean id="counter" class="counter" scope="request"/>
    <%
    //调用counter对象的ReadFile方法来读取文件da.txt中的计数
    String cont=counter.ReadFile("da.txt");
    String str="";
    if(session.getAttribute("da")==null)  
    {  
       //计数器加1  
      char[] c = cont.toCharArray();
      for(int i = 0; i < c.length; i++){
        str=str+"<img src='images/count"+c[i]+".gif'>";
      }
        counter.WriteFile("da.txt",cont);
        session.setAttribute("da","ok"); 

    out.println(str);
    %>counter.java如下:
    import java.io.*;public class counter extends Object {
      private String currentRecord = null;//保存文本的变量
      private BufferedReader file; //BufferedReader对象,用于读取文件数据
      private String path;//文件完整路径名
      public counter() {
      }
      //ReadFile方法用来读取文件filePath中的数据,并返回这个数据
      public String ReadFile(String filePath) throws FileNotFoundException
      {
        path = filePath;
        //创建新的BufferedReader对象
        file = new BufferedReader(new FileReader(path));
        String returnStr =null;
       try
       {
          //读取一行数据并保存到currentRecord变量中
          currentRecord = file.readLine();
        }
        catch (IOException e)
        {//错误处理
          System.out.println("读取数据错误.");
        }
        if (currentRecord == null)
        //如果文件为空
           returnStr = "没有任何记录";
        else
        {//文件不为空
           returnStr =currentRecord;
         }
         //返回读取文件的数据
         return returnStr;
      }
      //ReadFile方法用来将数据counter+1后写入到文本文件filePath中
      //以实现计数增长的功能
      public void WriteFile(String filePath,String counter) throws FileNotFoundException
      {
        path = filePath;
        //将counter转换为int类型并加一
        int Writestr = Integer.parseInt(counter)+1;
        try {
           //创建PrintWriter对象,用于写入数据到文件中
           PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
          //用文本格式打印整数Writestr
          pw.println(Writestr);
          //清除PrintWriter对象
          pw.close();
        } catch(IOException e) {
        //错误处理
          System.out.println("写入文件错误"+e.getMessage());
        }
      }}
      

  4.   

    楼上的,主段不行呀,出错<%@ page contentType="text/html;charset=GB2312" %>
    <%@ page import="java.io.*" %>
    <HTML>
    <style type="text/css">
    <!--
    .style1 {color: #FF0000}
    -->
    </style>
    <BODY ><FONT Size=2>
        <%! 
    int number=0;     
         synchronized void countPeople()//计算访问次数的同步方法
            { 
             if(number==0)
                 { 
                   try{ 
                      FileInputStream in=new FileInputStream("c:\\count.txt");
                      DataInputStream dataIn=new DataInputStream(in);
                      number=dataIn.readInt();
                      number++;
                      in.close();
                      dataIn.close();
                     }
                      catch(FileNotFoundException e)
                       { number++;
                        try {FileOutputStream out=new FileOutputStream("c:\\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("c:\\count.txt");
                      DataOutputStream dataOut=new DataOutputStream(out);
                      dataOut.writeInt(number);
                      out.close();dataOut.close();
                   }
                 catch(FileNotFoundException e){}
                 catch(IOException e){}
               }
         }
       %>
       <% 
          countPeople();
       %>
    <P><P>您是第
       <span class="style1"><font size="+2"><%=number%></font></span>
     个访问本站的客户。
    <BODY>
    <HTML>
      

  5.   

    if(session.hasNew())
    count++;
    else
    count=count;