java 网站计数器_Java Bean实现网页来访计数器
1.JSP頁:
Document?? : index
Created on : 2009-10-10, 14:47:46
Author???? : lucifer
--%>
/p>
"http://www.w3.org/TR/html4/loose.dtd">
JSP PageWelcome!!
You're the
String url = "C:\\Users\\lucifer\\Desktop\\count.txt";
//改成自己的text文件,用來計數(shù)
count.setPath(url);
count.setCount();
out.println(count.getCount());
%>
Visitor!!!
2.Bean:
package MyBean;
import java.io.*;
/**
*
* @author lucifer
*/
public class Counter {
private String url;
private String count;
public void setPath(String url){
this.url = url;
}
public String getCount(){
try{
BufferedReader br;
br = new BufferedReader(new FileReader(url));
count = br.readLine();
br.close();
return count;
}
catch(IOException e){
e.printStackTrace();
return "No Record!";
}
}
public void setCount(){
try{
BufferedReader br = new BufferedReader(new FileReader(url));
count = new String(br.readLine());
int num;
if(count == null)
num = 1;
else
num = Integer.parseInt(count) + 1;
try{
PrintWriter pw = new PrintWriter(new FileOutputStream(url));
pw.println(num);
pw.close();
}
catch(IOException e){
System.out.println(e.getMessage());
}
br.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}
總結(jié)
以上是生活随笔為你收集整理的java 网站计数器_Java Bean实现网页来访计数器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 格林美是做什么的公司 强势涨停且后劲十足
- 下一篇: 附加险背后的智慧,保险公司十分聪明