初学者问题,javabean计数器高分求解
出错:http://yu.40it.com/jsp/count2.jsp
文件:
counter.java
package counter;
import java.io.*;
public class counter extends Object
{
public String path = "";
public String doCount() throws FileNotFoundException
{
BufferedReader file; //BufferedReader对象,用于读取文件数据
String countFile = path;
//读取count.txt中的访问人数
file = new BufferedReader(new FileReader(countFile));
String readStr = "";
int writeStr = 1; //如果数据库为空则让它显示时变成1并写入
try
{
readStr = file.readLine();
}
catch(IOException e) {
System.out.println("读取数据错误.");
}
if (readStr == "")
{
readStr = "没有任何记录"; //访问人数加1
} else {
writeStr = Integer.parseInt(readStr) + 1;
}
//将新的访问人数写入count.txt
try
{
PrintWriter pw = new PrintWriter(new FileOutputStream(countFile));
pw.println(writeStr);
pw.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
return readStr;
}
}
count2.jsp
<HTML>
<HEAD>
<meta http-equiv="Content_Type" content="text/html;charset=gb2312">
<META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
<TITLE>计数器JavaBeans版本</TITLE>
</HEAD>
<BODY bgcolor="#ffffff">
<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">
<H1>计数器JavaBeans版</h1>
<H3>你是本网页的第<font color="ff0000" size="7">
<%=count%>
</font>名访客!</h3>
</BODY>
</HTML>