>  기사  >  Java  >  Java 웹사이트 방문 통계

Java 웹사이트 방문 통계

高洛峰
高洛峰원래의
2017-01-23 17:06:501490검색

고객이 웹사이트를 방문하면 이 파일을 읽고, 서버가 재시작되기 전의 카운트를 읽고, 1을 증가시킨 후, 새로운 카운트를 파일에 씁니다.

참조 코드는 다음과 같습니다.

100db36a723c770d327fc0aef2ce13b1

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Insert title here</title> 
</head> 
<body> 
  <%! 
    int number = 0; 
    File file = new File("count.txt"); 
    synchronized void countPeople() 
    { 
      if(!file.exists()) 
      { 
        number++; 
        try{ 
          file.createNewFile(); 
          FileOutputStream out = new FileOutputStream("count.txt"); 
          DataOutputStream dataOut = new DataOutputStream(out); 
          dataOut.writeInt(number); 
          dataOut.close(); 
        }catch(IOException ex){} 
      } 
      else  
        try{ 
          FileInputStream in = new FileInputStream("count.txt"); 
          DataInputStream dataIn = new DataInputStream(in); 
          number = dataIn.readInt(); 
          number++; 
          in.close(); 
          dataIn.close(); 
          FileOutputStream out = new FileOutputStream("count.txt"); 
          DataOutputStream dataOut = new DataOutputStream(out); 
          dataOut.writeInt(number); 
          out.close(); 
          dataOut.close(); 
        }catch(IOException ex){} 
    } 
  %> 
  <% 
    countPeople(); 
  %> 
  <p> 
    您是第 
    <%=number %> 
    个访问网站的客户。 
  </p> 
</body> 
</html>

위 내용은 모두의 학습에 도움이 되기를 바랍니다. 또한 모두가 PHP 중국어를 배워보시길 바랍니다.网

자바 웹 사이트 방문 통계에 관한 더 많은 기사를 보려면 PHP 중국어 사이트를 주목해주세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.