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

JSP
jsp计数器制作
用jsp编写文件上载
基于JSP的动态网站开发技术
JSP由浅入深(3)—— 通过表达式增加动态内容
JSP由浅入深(5)—— Scriptlets和HTML的混合
JSP由浅入深(1)—— 熟悉JSP服务器
JSP由浅入深(12)—— 表单编辑
JSP由浅入深(11)—— 标记库
JSP由浅入深(10)—— Beans and Forms处理
JSP由浅入深(9)—— JSP Sessions
JSP由浅入深(8)—— JSP Tags
JSP由浅入深(6)—— JSP声明
JSP由浅入深(4)—— Scriptlets
JSP由浅入深(2)—— 第一个JSP
JSP由浅入深(7)—— JSP Directives
JSP中的字符替换函数 str_replace() 实现!
把一张图片变形扭曲成各种不同的长宽
用JSP编写通用信息发布程序
Java Servlet及Cookie的使用
Apache+Servlet+Jsp环境设置(上)

JSP 中的 jsp计数器代码


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