JSP计数器
来源:互联网 发布:淘宝链接是什么 编辑:程序博客网 时间:2024/04/27 18:51
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="Java" import="java.io.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计数器</title>
</head>
<%!
//同步更新计数器
synchronized void counter(){
ServletContext application=getServletContext(); //构造application对象(可选)
String szPath=application.getRealPath("/"); //得到当前路径
szPath=szPath+"hits.txt"; //计数器文件 0-9999999999999...
String szRecord=""; //记数 String
int nRecord=0; //记数 int
try{
BufferedReader file=new BufferedReader(new FileReader(szPath));
szRecord=file.readLine(); //读取计数器文件
}
catch(IOException e){
e.printStackTrace(System.err);
}
if(szRecord==null) szRecord="0"; //如果计数器文件为空
nRecord=java.lang.Integer.parseInt(szRecord)+1; //计数器+1
try{
File f=new File(szPath);
PrintWriter pw=new PrintWriter(new FileWriter(f));
pw.print(nRecord); //写文件
pw.close();
}
catch(IOException e){
System.out.println(e);
}
}
%>
<%
//显示计数器
if(session.isNew()){ //如果是新用户
counter();
}
String Path=application.getRealPath("/");
String szPath=Path+"hits.txt";
String szRecord="";
BufferedReader file=new BufferedReader(new FileReader(szPath));
try{
szRecord=file.readLine();
}
catch(IOException e){
System.out.println("文件未找到!");
}
//显示7位数字gif图像
String szOut="<body topmargin='0' leftmargin='0'>";
int i=0;
int k=7-szRecord.length(); //"0"的个数
for (i=0;i<k-1;i++){ //显示"0"
szOut=szOut+"<img src='images/0.gif'>";
}
for (i=0;i<szRecord.length();i++){ //显示非"0"
szOut=szOut+"<img src='images/"+ szRecord.charAt(i) +".gif'>";
}
szOut=szOut+"</body>";
out.println(szOut);
%>
</html>
- JSP 计数器
- JSP计数器
- JSP计数器
- jsp计数器
- 简单的计数器(jsp)
- jsp计数器制作手册
- jsp计数器代码
- jsp计数器制作手册
- jsp计数器代码
- jsp计数器制作手册
- jsp计数器制作
- jsp简单计数器
- 网站计数器-jsp编程
- jsp 网页计数器代码
- jsp网页计数器
- jsp简单页面计数器
- jsp网站访问量计数器
- jsp网站访问量计数器
- Berkeley DB Java Edition 基本示例
- JSP数据库连接大全
- 通过了PMP考试
- Ruby中的数组和散列表(一)
- windows xp/2003 自动登陆
- JSP计数器
- JSP分页技术,很不错
- 7-23错误处理&数据缓存
- JSP(Struts)避免Form重复提交的三种方案
- JDK1.4安装与环境配置完全图解(windows)
- GOOGLE的摄像头漏洞
- Javscript实现表单复选框的全选功能
- Java中对XML四种操作方式的使用
- 第3章 静态建模: 用例和用例图