服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

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


  做一个带有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>

扫描关注微信公众号