下载此文档

JSP中实现网页访问统计的方法.docx


文档分类:IT计算机 | 页数:约14页 举报非法文档有奖
1/14
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/14 下载此文档
文档列表 文档介绍
}
JSP中实现网页访问统计的方法
}
原创 2012-09-21 15:13:17
我来说两句
作者:wwj_748
}
}
网络所得:未经验证
JSP中实现网页访问统计的方法
最近学习Java
计数器程序</title>
</head>
<body>
<%
int n = 0; String coun ter = (Stri ng)a pp licati on. getAttribute("co un ter");
if(co un ter != n ull){
n = In teger. parse In t(co un ter);
if(sessio n. isNew())
++n;
%>
<center> 这是第 <%(n);%> 个访问者 </center>
<%
coun ter = Strin ( n);
app licati on. setAttribute("co un ter", coun ter);
%>
</body>
</html>
<%***@page Ian guage="java
imp ort=".*"
pageE ncodi ng="GB2312"%>
}
<html>
<head>
<title>java
计数器程序
</title>
</head>
<body>
<%
int n = 0; String coun ter
=(Stri ng)a pp licati on. getAttribute("co un ter");
if(co un ter != nu ll){
n = In teger. parse In t(co un ter);
if(sessio n. isNew())
}
();
++n;
%>
<center> 这是第 <%(n);%> 个访问者 </center>
<%
coun ter = Strin ( n);
app licati on. setAttribute("co un ter", coun ter);
%>
</body>
</html>
txt文件当
第三种方法是将统计数据存储在本地的文件当中,比如存储在一个
中。
这是为了解决重启服务器之后数据不用担心会丢失。
创建一个类:JSP Cou nt
[java]
import ;
import ;
import oun dExce ptio n;
import ;
import ;
import pti on;
import . Prin tWriter;
public class JSP Cou nt {
// 写入文件的方法
p ublic static void write2File(Stri ng file name, I ong coun t){
try{
Prin tWriter out = new Prin tWriter( new FileWriter(file name));
out. println(coun t);
} catch (IOExce pti on e) {
();
}
tStackTrace();
// TODO: han die exce ption
tStackTrace();
//
读文件的方法
();
}
tStackTrace();
p ublic static long readFromFile(Stri ng file name){
File file = new File(file name);
long count = 0;
if(!()){
try {
();
} catch (IOExce pti on e) {
// TODO Auto-ge nerated catch block
tStackTrace();
write2File(file name, 0);

JSP中实现网页访问统计的方法 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数14
  • 收藏数0 收藏
  • 顶次数0
  • 上传人0640105
  • 文件大小38 KB
  • 时间2022-04-07