做一个带有beans的文字计数器
2008-01-05 09:41:26 来源:WEB开发网核心提示:做一个带有beans的文字计数器 访问计数器程序:counter.java package counter; import java.io.*; public class counter { public String path=""; public String doCo
做一个带有beans的文字计数器
访问计数器程序: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>
<T99vLE>
counter
</T99vLE>
</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>
赞助商链接