Java web網(wǎng)站訪問量的統(tǒng)計(jì)
當(dāng)客戶訪問網(wǎng)站時(shí)就去讀這個(gè)文件,將服務(wù)器重新啟動(dòng)前的計(jì)數(shù)讀入,并在此基礎(chǔ)上增加1,然后將新的計(jì)數(shù)寫入到文件中。
參考代碼如下:
<html>
<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 %> 個(gè)訪問網(wǎng)站的客戶。 </p> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- JavaScript實(shí)現(xiàn)網(wǎng)站訪問次數(shù)統(tǒng)計(jì)代碼
- JS 精確統(tǒng)計(jì)網(wǎng)站訪問量的實(shí)例代碼
- 一個(gè)簡(jiǎn)單的網(wǎng)站訪問JS計(jì)數(shù)器 刷新1次加1次訪問
- ASP.net中網(wǎng)站訪問量統(tǒng)計(jì)方法代碼
- 利用google提供的API(JavaScript接口)獲取網(wǎng)站訪問者IP地理位置的代碼詳解
- javascript實(shí)現(xiàn)的網(wǎng)站訪問量統(tǒng)計(jì)代碼
- Windows Server 2008 R2網(wǎng)站訪問PHP響應(yīng)慢的解決方法
- Javascript自定義函數(shù)判斷網(wǎng)站訪問類型是PC還是移動(dòng)終端
- python實(shí)現(xiàn)用于測(cè)試網(wǎng)站訪問速率的方法
- php獲得網(wǎng)站訪問統(tǒng)計(jì)信息類Compete API用法實(shí)例
相關(guān)文章
SpringBoot整合canal實(shí)現(xiàn)數(shù)據(jù)同步的示例代碼
本文主要介紹了SpringBoot整合canal實(shí)現(xiàn)數(shù)據(jù)同步,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03關(guān)于springBoot yml文件的list讀取問題總結(jié)(親測(cè))
這篇文章主要介紹了關(guān)于springBoot yml文件的list讀取問題總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12shuffle的關(guān)鍵階段sort(Map端和Reduce端)源碼分析
今天小編就為大家分享一篇關(guān)于shuffle的關(guān)鍵階段sort(Map端和Reduce端)源碼分析,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-01-01Spring Boot 2.0 設(shè)置網(wǎng)站默認(rèn)首頁(yè)的實(shí)現(xiàn)代碼
這篇文章主要介紹了Spring Boot 2.0 設(shè)置網(wǎng)站默認(rèn)首頁(yè)的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-04-04