public class Counter {
private int count;
// 每訪問一次,計數器自加一
public int getCount() {
return ++count;
}
public void setCount(int count) {
this.count = count;
}
}
<%-- 定義一個 session 范圍內的計數器 記錄個人訪問信息 --%>
<jsp:useBean id="personCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="session" />
<%-- 定義一個 application 范圍內的計數器 記錄所有人的訪問信息 --%>
<jsp:useBean id="totalCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="application" />
<div align="center">
<form action="method.jsp" method="get">
<fieldset style='width: 300'>
<legend>計數器</legend>
<table align="center" width="400">
<tr>
<td width=150 align="right" style="font-weight:bold; ">您的訪問次數:</td>
<td>
<%-- 獲取個人的 訪問次數 --%>
<jsp:getProperty name="personCount" property="count" /> 次
</td>
</tr>
<tr>
<td width=150 align="right" style="font-weight:bold; ">總共的訪問次數:</td>
<td>
<%-- 獲取所有人的 訪問次數 --%>
<jsp:getProperty name="totalCount" property="count" /> 次
</td>
</tr>
</table>
</fieldset>
</form>
</div>
希望你能幫到你
『貳』 求一個網頁計數代碼 HTML
1.這個是寫asp網頁計數器的。
Functions.asp文件代碼
<%
Function Counts(CounterFile)
Dim objFSO, objTS
Application.Lock
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(Server.MapPath(CounterFile), 1, True)
If Not objTS.AtEndOfStream Then '檢查是否到達文件結尾
Counts = CLng(objTS.ReadLine)
End If
Counts = Counts + 1
objTS.Close
Set objTS = objFSO.OpenTextFile(Server.MapPath(CounterFile), 2, True)
objTS.WriteLine(Counts)
objTS.Close
Application.Unlock
End Function
%>
顯示統計效果
<HTML>
<BODY>
<!-- #include file="Functions.asp" -->
<%
If Session("Counter") = Empty Then
Session("Counter") = Counts("Count.txt")
End If
%>
<%= Session("Counter") %>
</BODY>
</HTML>
建一個Count.txt文件,裡面寫一個初始值,絕對可用的ASP網頁計數器代碼。
2.
<script language=JavaScript>today=new Date();
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray(
" 星期日",
" 星期一",
" 星期二",
" 星期三",
" 星期四",
" 星期五",
" 星期六");
document.write("<font style='font-size:9pt;font-family: 宋體'> ",
today.getYear(),"年",
today.getMonth()+1,"月",
today.getDate(),"日",
d[today.getDay()+1],
"</font>");
</script>
3.
這是一段PHP代碼,主控時間取自伺服器時間(避免客戶端時間的失准),但是原理是基於JS的,稍加改寫即可用於不同平台.
<?
####<讀入系統時間功能>####
function nowtime(){
$date=date("m/d/Y");
return $date;
}?>
<?php $time = nowtime()?>
<script language="javascript">
var urodz= new Date("10/18/2003"); //指定欲比較的日期
var now = new Date("<?php echo $time ?>");//獲得當前伺服器日期
var ile = urodz.getTime() - now.getTime() ;//做比較
var dni = Math.floor(ile / (1000 * 60 * 60 * 24))+1;
if (dni > 1)
document.write("距日10/18/2003還有<font color=red size=20pt>"+dni+"</font>天")
else if (dni == 1)
document.write("只有2天啦!")
else if (dni == 0)
document.write("今天就是啊!")
else
document.write("好象已經過了哦!");
</script>