求教:计数器中javaBean的功能问题(解决立刻结分)
我的bean是这样写的:
import java.io.*;
public class Count{
//保存文本的变量
private String currentRecord = null;
private BufferedReader file;
//文本完整路径名
private String path;
public Count(){}
//读取数据
public String readFile(String filePath) throws FileNotFoundException{
path = filePath;
file = new BufferedReader(new FileReader(path));
String returnStr = null;
try{
currentRecord = file.readLine();
}
catch(IOException e){
System.out.println("读取数据错误。");
}
if (currentRecord == null){
returnStr = "0";
}else{
returnStr = currentRecord;
}
return returnStr;
}
//写入数据
public void writeFile(String filePath,String count) throws FileNotFoundException{
path = filePath;
int writeStr = Integer.parseInt(count) + 1;
try{
PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
pw.println(writeStr);
pw.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}
编译后放入:WEB-INF》classes中,JSP调用方式如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<JSP:useBean id="Count" class="Count" scope="request">
</JSP:useBean>
<%String txtPath;
txtPath = request.getRealPath("count.txt");
String count = Count.readFile(txtPath);
synchronized(txtPath){
Count.writeFile(txtPath,count);
}
%>
</body>
</html>
但出来的错误为:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:\Apache Group\Tomcat 4.1\work\Standalone\localhost\tobacco\count_jsp.java:54: cannot resolve symbol
[javac] symbol : variable Count
[javac] location: class org.apache.jsp.count_jsp
[javac] String count = Count.readFile(txtPath);
[javac] ^
[javac] C:\Apache Group\Tomcat 4.1\work\Standalone\localhost\tobacco\count_jsp.java:56: cannot resolve symbol
[javac] symbol : variable Count
[javac] location: class org.apache.jsp.count_jsp
[javac] Count.writeFile(txtPath,count);
[javac] ^
[javac] Note: C:\Apache Group\Tomcat 4.1\work\Standalone\localhost\tobacco\count_jsp.java uses or overrides a deprecated API.
[javac] Note: Recompile with -deprecation for details.
[javac] 2 errors
=================
请问我该如何解决,我里边写了Count Count = new Count();也说没有Count,到底是怎么回事,请赐教!!!谢谢!!!