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

JSP
我认为JSP有问题(下)
JSP显示中文问题的解决方案
JSP技术简介
JSP开发导引
JSP开发入门
JSP多种web应用服务器导致JSP源码泄漏漏洞
JSP实现浏览器关闭cookies情况下的会话管理
tomcat 3.1在RedHat下的安装
初学jsp心得
如何防止IE缓存jsp文件
利用Java实现zip压缩/解压缩
一个用JSP做的日历
无边框窗口代码详解
实例讲解JSP Model2体系结构(上)
实例讲解JSP Model2体系结构(中)
实例讲解JSP Model2体系结构(下)
JSP模板应用指南(下)
JSP简明教程:令人兴奋的脚本编程
JSP简明教程:对比与总结
jsp基础学习资料

JSP 中的 jsp计数器代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 45 ::
收藏到网摘: 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);
%>