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>