首页 域名主机 文章教程 汽车频道 酷车图集 博客之家 网址之家 资源下载 在线音乐 本站论坛
  你现在的位置:首页>>文章教程>>网页编程>>JSP教程>>正文
 
 jsp计数器代码
 
[2005-3-24] 来源:lovemz.com 作者:分享吧收集整理  爱我梅州商务网 
 

<!--
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);
%>

 
上一篇文章: jsp源码实例1(输出)
下一篇文章:jsp文件操作之追加篇
本文章为原作者版权所有,如有侵犯您的权益请通知我们,我们会在24小时以内删除
最新5篇热点文章
最新5篇推荐文章
相关文章


关于我们 | 广告刊登 | 合作伙伴 | 友情链接 | 意见反馈 | 帮助HELP| 网站地图

版权所有 Copyright © 2002-2005 爱我梅州商务网
粤ICP备05105236号