| 关键词: nbsp 机器码 寄存器 标志 指令 操作数 字节 运算 指针 地址 |
<%--用application对象实现网页计数器--%><%@ page contentType="text/html;charset=gb2312"%><html><head><title>网页计数器</title><head><body bgcolor="cyan" ><% if (application.getAttribute("counter")==null)application.setAttribute("counter","1");else{ String strnum=null; strnum=application.getAttribute("counter").toString(); int icount=0; icount=Integer.valueOf(strnum).intValue(); icount++; application.setAttribute("counter",Integer.toString(icount)); } %>您是第<%=application.getAttribute("counter")%>位访客!</body></html> (2)jsp计数 <%@ page contentType="text/html;charset=gb2312" %><html><head><title>计数器</title></head><body bgcolor="#ffffff"><h1>一个简单的计数器</h1><%try {//使用io操作实现文件的读写,counter.txt是用来存放计数的,如果不存在,就在本目录下创建java.io.FileReader fr=new java.io.FileReader(request.getRealPath("/")+"\\counter.txt");java.io.BufferedReader br = new java.io.BufferedReader(fr);String count = br.readLine();if (count == null) {counter.txt里的计数为空的话,就向里写入一个初值1 java.io.FileWriter fw=new java.io.FileWriter(request.getRealPath("/")+"\\counter.txt"); java.io.PrintWriter pw=new java.io.PrintWriter(fw); pw.print("1"); pw.close(); fw.close();}else{ 不为空的话,在原来计数上加1out.println("本页面是第"+count+"次被访问!!"); java.io.FileWriter fw=new java.io.FileWriter(request.getRealPath("/")+"\\counter.txt"); java.io.PrintWriter pw=new java.io.PrintWriter(fw); pw.print(String.valueOf(Integer.parseInt(count)+1) ); pw.close(); fw.close();}}catch(Exception e){ java.io.FileWriter fw=new java.io.FileWriter(request.getRealPath("/")+"\\counter.txt"); java.io.PrintWriter pw=new java.io.PrintWriter(fw); pw.print("1"); out.println("本页面是第"+1+"次被访问!!"); pw.close(); fw.close();}%></body></html> 您是第位访客! 第一次运行计数是1 没刷新一次,计数增加一次 |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|