当前位置: 首页 > 图文教程 > 网络编程 > JSP > jsp计数器代码

JSP
用JSP实现的一个日历程序
JSP生成jpeg图片用于投票
按IE后退按钮时让JSP不读缓存
JSP简介
Tomcat+Jsp环境下的中文问题
JSP技术生成动态web页面
在JSP中访问MS SQL Server数据库
从jsp发送动态图像
JSP/Servlet 中的汉字编码问题
困扰JSP的一些问题与解决方法
高效的jsp分页查询
JSP动态输出Excel及中文乱码的解决
JavaBean实现多文件上传的两种方法
加快JDBC设计中JSP访问数据库
将JSP在内存生成的图片显示到页面
[JAVA]十四种Java开发工具点评
JSP/Servlet应用程序优化八法
初学java常用开发工具介绍
JSP连接SQL Server 2000系统配置
win2000server IIS和tomcat5多站点配置

JSP 中的 jsp计数器代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 66 ::
收藏到网摘: n/a

<!--
JSP-Hitcounter counts sessions.
Copyright (C) 2000 Jesper Schmitz Mouridsen.
Visit www.webappcabaret/jsm2/webapps.jsp?find=jsphcs for more info.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at http://www.opensource.org/licenses/gpl-license.html for more details
-->

<%
BufferedReader inf = new BufferedReader(new FileReader("/path/to/counter.txt"));
int tmp = Integer.parseInt(inf.readLine());
int i=0;
try {
i = Integer.parseInt(request.getSession().getValue("tal").toString());
} catch (NullPointerException t) {i=0; }
if (i==0) {
tmp++;
PrintWriter outf = new PrintWriter(new BufferedWriter(new FileWriter("/path/to/counter.txt")));
outf.println(tmp);
outf.close();
inf.close();
request.getSession().putValue("tal", "1");
}
BufferedReader inf2 = new BufferedReader(new FileReader("/path/to/counter.txt"));
%>
<%
String zeroes="";
String hits = inf2.readLine();
inf2.close();
for (int t=0; t < 8-hits.length(); t++) {
zeroes=zeroes+"0"; }
out.println(zeroes + hits);
%>