jsp计数器代码

所属分类: 网络编程 / JSP编程 阅读数: 643
收藏 0 赞 0 分享
<!--
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);
%>

更多精彩内容其他人还在看

weblogic 8.1下重新编译java类但不用重启服务器的方法

weblogic 8.1下重新编译java类但不用重启服务器的方法
收藏 0 赞 0 分享

JSP下动态INCLUDE与静态INCLUDE的区别分析

这篇文章给大家介绍了JSP下动态INCLUDE与静态INCLUDE的区别分析,非常不错,具有一定的参考借鉴价值,需要的朋友参考下吧
收藏 0 赞 0 分享

jsp中文乱码 jsp mysql 乱码的解决方法

当使用JSP页面将中文数据添加到MySql数据库中的时候发现变为乱码,或者从mysql中读取中文的时候出现乱码,这些问题根源都是由于字符编码不一致造成的。本文介绍jsp mysql 乱码的解决方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Jsp页面实现文件上传下载类代码第1/2页

Jsp页面实现文件上传下载类代码
收藏 0 赞 0 分享

下载完成后页面不自动关闭的方法

其实就一句话js代码,window.close()
收藏 0 赞 0 分享

JBuilder2005实现重构

JBuilder2005实现重构
收藏 0 赞 0 分享

CORBA对象生命周期

CORBA对象生命周期
收藏 0 赞 0 分享

基于Java的代理设计模式

基于Java的代理设计模式
收藏 0 赞 0 分享

Java中四种XML解析技术

Java中四种XML解析技术
收藏 0 赞 0 分享

跨平台Java程序

跨平台Java程序
收藏 0 赞 0 分享
查看更多