做一个带有beans的文字计数器

发表于:2007-06-17来源:作者:点击数: 标签:
访问计数器程序:counter. java package counter; import java.io.*; public class counter { public String path=""; public String doCount() throws FileNotFoundException { BufferedReader file; String countFile=path; file=new BufferedReader(new F

   
  访问计数器程序:counter.java

package counter;
import java.io.*;
public class counter {
public String path="";
public String doCount() throws FileNotFoundException
{
BufferedReader file;

String countFile=path;
file=new BufferedReader(new FileReader(countFile));
String readStr="";
int writeStr=1;
try
{
readStr=file.readLine();
}
catch(IOException e)
{
System.out.println("读取数据错误.");
}

if(readStr=="") readStr="没有任何记录";
else
{
writeStr=Integer.parseInt(readStr)+1;
}

try
{
PrintWriter pw=new PrintWriter(new FileOutputStream(countFile));
pw.println(writeStr);
pw.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
return readStr;
}
}

counter.jsp代码如下:
<HTML>
<HEAD>
<TITLE>
counter
</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="counter" scope="request" class="counter.counter" />
<%@ page contentType="text/html;charset=gb2312"%>
<%
counter.path="count.txt";
String count=counter.doCount();
%>
<p align="center">
<H3 align="center"><font color="#993300" size="5">您好!您是本系统的第
<font color="ff0000"><%=count%> </font>
名访问者!</font></H3>
</body>
</html>

原文转自:http://www.ltesting.net

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)