×

网页计数器代码html

网页计数器代码html(用jsp编写一个实现页面计数的计数器,要求当刷新页面时,不增加计数)

admin admin 发表于2024-01-26 13:37:56 浏览29 评论0

抢沙发发表评论

各位老铁们好,相信很多人对网页计数器代码html都不是特别的了解,因此呢,今天就来为大家分享下关于网页计数器代码html以及用jsp编写一个实现页面计数的计数器,要求当刷新页面时,不增加计数的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!

本文目录

用jsp编写一个实现页面计数的计数器,要求当刷新页面时,不增加计数

《%@ page language="java" import="java.util.*" pageEncoding="utf-8"%》《%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%》《!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"》《html》 《head》 《base href="《%=basePath%》"》 《title》网页计数器《/title》 ***隐藏网址******隐藏网址******隐藏网址******隐藏网址******隐藏网址*** 《!-- 《link rel="stylesheet" type="text/css" href="styles.css"》 --》 《/head》 《body》 《% if(application.getAttribute("counter")==null) { application.setAttribute("counter",1); } else { String str=application.getAttribute("counter").toString(); int icount=Integer.parseInt(str); if(session.isNew()) { icount++; } application.setAttribute("counter",Integer.toString(icount)); } %》 您是第《%=application.getAttribute("counter") %》位。 《/body》《/html》

用css js做一个网页版的计算器,要有加减乘除运算,和归零删除键

《!DOCTYPE html》《html lang="en"》《head》《meta charset="UTF-8"》《title》计数器《/title》《/head》《body》《input type="text" name="text" id="pre" onblur="validate(this.value);"》《select id="operator"》《option value="+"》+《/option》《option value="-"》-《/option》《option value="*"》*《/option》《option value="/"》/《/option》《/select》《input type="text" name="text" id="next" onblur="validate(this.value);"》《span》=《/span》《input type="text" id="result" readonly="true"》《input type="button" id="btn" value="提交" onclick="calculator();"》《script》function validate(str){var reg = /^\d+$/; if (!reg.test(str)) { alert("请输入数字"); }}function calculator(){var pre=document.getElementById("pre").value;var next=document.getElementById("next").value;var opra=document.getElementById("operator").value;var result=0;switch(opra) {case "+":result=parseInt(pre)+parseInt(next);break;case "-":result=parseInt(pre)-parseInt(next);break;case "*":result=parseInt(pre)*parseInt(next);break;case "/":if(parseInt(next)!=0){result=parseInt(pre)/parseInt(next);}else{alert("除数不能为0");return;}break;default:break;}document.getElementById("result").value=result;}《/script》《/body》《/html》

如何实现HTML 记录点击次数

以下介绍用数据库实现简单计数器 ’下面存为count.asp 《% Set conn=Server.CreateObject("ADODB.Connection") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& Server.MapPath("count.mdb") %》 《%on error resume next%》 《%sql="update count set hit=hit+1%》《%conn.Execute(sql)%》 《%sql = "select * from count set rs=conn.execute(sql) %》 《% ’更新每周每日数据 lasthit=rs("lasthit") tdate=year(Now()) & "-" & month(Now()) & "-" & day(Now()) if trim(lasthit)=trim(tdate) then sql="update site set dayhit=dayhit+1 where id="&request("id") conn.Execute(sql) ’ response.write "success" else sql="update site set dayhit=1 where id="&request("id") conn.Execute(sql) ’ response.write "error" end if sql="update site set lasthit=’"&tdate&"’ where ID="&request("id") conn.Execute(sql) p_year=CInt(year(Now()))-CInt(year(lasthit)) p_month=CInt(month(Now()))-CInt(month(lasthit)) p_day=CInt(day(Now()))-CInt(day(lasthit)) period_time=((p_year*12+p_month)*30+p_day) if cint(period_time)=《cint(7) then sql="update site set weekhit=weekhit+1 where id="&request("id") conn.Execute(sql) else sql="update site set weekhit=1 where id="&request("id") conn.Execute(sql) end if %》 document.write(’《tr》《td width="100%"》今日访问《%=rs("dayhit")%》次,本周访问《%=rs("weekhit")%》次,总访问《%=rs("hit")%》次《/td》《/tr》’); 《%rs.close set rs=nothing%》 ’用《script language="JavaScript1.1" src="count.asp"》《/script》在要统计的页面调用即可. 建立数据库:建一个count的MDB库,再建一个表count,表中字段为 hit 数字型 dayhit 数字型 weekhit 数字型 lasthit 日期型 静态: 在静态页面中显示文章被阅读的次数 在文章发布系统中采用服务器端生成静态页面的方法可以有效减轻服务器的负担,特别是对大流量网站非常有效。但是既然生成的是静态页面,生成时是什么样,显示就是什么样了,对于文章常见文章被阅读次数怎么显示呢? 经考虑,可用如下方案解决: 生成静态页面时会产生一个文章的id存到数据库中,那么我们在制作文章的模板的时候就可以在这个文章的id上做文章,文章模板包含以下语句: 《SCRIPT src="counter.asp?articleId=《%=#articleId#%》"》《/SCRIPT 》 《b》说明:《/b》 在利用模板生成文章时,把"#articleId#"进行模式匹配,替换为新添加的文章的id号。 counter.asp 文件为实现记数的asp文件 《% ’################### ’######开始######### ’BY 王向超 ’################### dim articleId,sqlStr,hits articleId=int(trim(request.querystring("articleId"))) sqlStr="update articles set hits=hits+1 where articleId=" & articleId ’给文章点击数加1 conn.execute(sqlStr) ’读出文章点击数 hits=conn.execute("select hits from articles where articleId=" & articleId)(0) %》 ’打印出文章点击数 document.write(《%=hits%》)

求一个网站计数器代码,要通用的HTML代码(分数不是问题,在线等)

这个用JSP的做法是: 《%@ page language="java" import="java.util.*" pageEncoding="GBK"%》 《% int count = 0; if(application.getAttribute("count") == null) { application.setAttribute("count",new Integer(count)); } else { count =Integer.parseInt(application.getAttribute("count").toString()); count ++; application.setAttribute("count", new Integer(count)); }%》 《p》共有《=count %》人访问过该网站 《/body》 《/html》

编写一个ASP程序,实现并显示当前网页的在线人数和计数器

在网站的根目录下,新建global.asa《SCRIPT LANGUAGE="VBScript" RUNAT="Server"》 Sub session_onstart Application.lock Application("online") = Application("online") + 1 Application.unlock End sub Sub session_onend Application.lock Application("online") = Application("online") - 1 End sub 《/SCRIPT》在其他页面中显示就可以了,如下《html》 《body》 《% session.timeout = 5%》 《P》在线人数:《% = Application("onlive") %》 《/P》 《/body》 《/html》 《% counter = Application("counter") + 1 %》 《html》《body》是第《%counter%》位访客 《%Application("counter") = counter %》 《/body》《/html》

html天数计数器代码,重金悬赏!!

《script language="javascript"》var now=new Date();var spday=new Date(2007,04-1,09);a=(now.getTime()-spday.getTime())/(24*60*60*1000);a=Math.ceil(a); document.write("《b》"+a+"《/b》");《/script》天 其中2007,04-1,09 是你要计算的天数起始日~(2007,04-1,09)=(西元年,月-1,日),(-1)的地方不要更动

网页中如何用代码设置网页访问计数器

1、将以下代码加在你需要得位置; 2、在根目录下创建名为count的文件夹,并在里面创建counter.txt文件,文件初始值为0(可更改); 3、将设置好的网页保存为.asp格式; 4、ok 您是第《span class="style2"》 《% Const ForReading = 1, ForWriting = 2, ForAppending =3 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 filepath=server.mappath("/count") filename=filepath+"\counter.txt" set fs=createobject("scripting.filesystemobject") if fs.fileexists(filename) then set f=fs.getfile(filename) Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault) s=ts.readline+1 ts.close else fs.createtextfile(filename) set f=fs.getfile(filename) s=1 end if ’向counter.txt中写数据 Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault) ts.writeline(cstr(s)) ts.close ’显示计数器 s=cstr(s+1000000) s=mid(s,2,8) for I=1 to 8 response.write mid(s,I,1) next %》 《/span》位访问者

用html实现访问量n+1

〈%Const ForReading = 1, ForWriting = 2, ForAppending =3Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0filepath=server.mappath("/count")filename=filepath+"\counter.txt"set fs=createobject("scripting.filesystemobject")if fs.fileexists(filename) thenset f=fs.getfile(filename)Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)s=ts.readline+1ts.closeelsefs.createtextfile(filename)set f=fs.getfile(filename)s=1end if’向counter.txt中写数据Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)ts.writeline(cstr(s))ts.close’显示计数器s=cstr(s+1000000)s=mid(s,2,6)for I=1 to 6response.write "〈img src=’../images/"∣(s,I,1)&".gif’ width=’18’ height=’25’》"next%》性急的朋友要问,你的这个计数器值显示6位计数,如果要显示8位计数,怎么办?别着急,等我讲完下一个例子我会给一个通式的。这个计数器有一个缺点,就是每次刷新页面计数器都加1,这是因为每刷新一次页面,系统认为你重新请求页面;而且,如果你不从主页面进入网站,计数器不会改变计数。如果想要更精确一点,只要将上面的代码略加修改,放到你的global.asa的session_onstart中,这样,只有新用户进入网站,计数器才会加1。已经进入网站的用户刷新页面,不会引起计数器计数的改变,而且不管你从哪个页面进站,计数器都能捕捉到你。〈script language=vbscript runat=server》sub application_onstartfilepath=server.mappath("/count")filename=filepath+"\counter.txt"set fs=createobject("scripting.filesystemobject")if not fs.fileexists(filename) thenfs.createtextfile(filename)set f=fs.getfile(filename)s=1Set ts = f.OpenAsTextStream(2, -2)ts.writeline(cstr(s))ts.closeelseset f=fs.getfile(filename)Set ts = f.OpenAsTextStream(1, -2)s=ts.readline+1ts.closeend ifapplication(“visitor”)=send subsub session_onstartsession.timeout=5application(“visitor”)=application(“visitor”)+1set f=fs.getfile(filename)Set ts = f.OpenAsTextStream(2, -2)ts.writeline (cstr(application(“visitor”)))ts.closeend sub〈/script》在网页相应部分根据application(“visitor”)的值显示计数器的图像。〈%s=cstr(application("visitor")+10^6)s=mid(s,2,6)for I=1 to 6response.write "〈img src=’../images/"∣(s,I,1)&".gif’ width=’18’ height=’25’》"next%》要显示n位计数器只要将上面代码改为:〈%s=cstr(application(“visitor”)+10 ^n)s=mid(s,2,n)for I=1 to nresponse.write "〈img src=’../images/"∣(s,I,1)&".gif’ width=’18’ height=’25’》"next%》这样要得到8位计数器,只要加上n=8即可。要是觉得每次有用户进入网站,均对counter.txt写入太频繁,可以在session_onstart中设置,在application(“visitor”)为十的倍数时将计数值写进counter.txt。计数器原理是:在第一次使用网页时置初始值1,以后每请求网页一次,将计数器值加1。这样我们只要在服务器上放置一个文本文件counter.txt,文本文件的内容有计数器的值,以后每请求一次页面,读出文本文件的计数器的数值,加1显示,然后再将原来的值改变为加1后的值,保存到文本文件。至于初始置1,在服务器上可先不建counter.txt,在网页中,先判断服务器上是否有counter.txt文件,没有就生成counter.txt,在counter.txt中写入1,网页上显示计数器值1,完成初始置1。以后每次只要到指定目录下将counter.txt文件删除即可置初始值

网页中的计数器问题

其中我们用到了两个文件,test.jsp文件用于在浏览器中运行,counter.java是后台的一个小java bean程序,用来读计数器的值和写入计数器的值。而对于计数器的保存,我们采用了一个文本文件lyfcount.txt。下面是详细的程序代码(test.jsp放到web目录下,counter.java放到class目录)://test.jsp文件$#@60;%@ page contentType="text/html;charset=gb2312"%$#@62;$#@60;HTML$#@62;$#@60;HEAD$#@62;***隐藏网址***$#@60;META NAME="GENERATOR" CONTENT="Oracle JDeveloper"$#@62;$#@60;TITLE$#@62;计数器演示程序$#@60;/TITLE$#@62;$#@60;/HEAD$#@62;$#@60;BODY$#@62;$#@60;!--创建并调用bean(counter)--$#@62;$#@60;jsp:useBean id="counter" class="counter" scope="request"$#@62;$#@60;/jsp:useBean$#@62;$#@60;%//调用counter对象的ReadFile方法来读取文件lyfcount.txt中的计数String cont=counter.ReadFile("/lyfcount.txt");//调用counter对象的ReadFile方法来将计数器加一后写入到文件lyfcount.txt中counter.WriteFile("/lyfcount.txt",cont);%$#@62;您是第$#@60;font color="red"$#@62;$#@60;%=cont%$#@62;$#@60;/font$#@62;位访问者$#@60;/BODY$#@62;$#@60;/HTML$#@62;//counter.java 读写文件的一个beanimport 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(pa );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));//用文本格式打印整数Writestrpw.println(Writestr);//清除PrintWriter对象pw.close();} catch(IOException e) {//错误处理System.out.println("写入文件错误"+e.getMessage());}}} 到这里,程序写完了,将counter.java编译为counter.class,同样放在对应的class目录下,在根目录下建立一个lyfcount.txt文件,文件内容就一个数字0,直接在浏览器中敲入地址就可以看到计数器了,刷新浏览器会看到不断变幻的数字。 (如果运行时候提示找不到文件,请将上面test.jsp中的readfile那一句注释后运行一次则lyfcount.txt文件自动建立,然后就可以正常运行。)

关于网页计数器代码html和用jsp编写一个实现页面计数的计数器,要求当刷新页面时,不增加计数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。