jsp计数器代码

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

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

JSP session配置对web应用的影响

这篇文章主要介绍了JSP session配置对web应用的影响的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

JSP开发中在spring mvc项目中实现登录账号单浏览器登录

这篇文章主要介绍了JSP开发中在spring mvc项目中实现登录账号单浏览器登录的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

利用JSP session对象保持住登录状态

这篇文章主要为大家详细介绍了如何利用JSP session对象保持住登录状态,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

jsp输出所有请求头的名称方法

下面小编就为大家带来一篇jsp输出所有请求头的名称方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

JSP 自定义注解及记录操作日志

这篇文章主要介绍了JSP 自定义注解及记录操作日志的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

JSP Struts过滤xss攻击的解决办法

这篇文章主要介绍了JSP Struts过滤xss攻击的解决办法的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

Spring AOP切面解决数据库读写分离实例详解

这篇文章主要介绍了Spring AOP切面解决数据库读写分离实例详解的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

Hibernate识别数据库特有字段实例详解

这篇文章主要介绍了Hibernate识别数据库特有字段实例详解的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

详解 hibernate mapping配置

这篇文章主要介绍了,每个hibernate只会启动的时候引入一个文件,那就是:hibernate.cfg.xml mapping需要我们在hibernate中引入, <mapping resource="com/hibernate/test/hibernate_I
收藏 0 赞 0 分享

JSP spring boot / cloud 使用filter防止XSS

这篇文章主要介绍了JSP spring boot / cloud 使用filter防止XSS的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多