日期:2014-05-18  浏览次数:20672 次

javaBean的工作机制是什么?我的javabean怎么总是报错?
jsp页面:--------------
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= "error.jsp "   %>
<!--创建并调用bean(counter)-->
<jsp:useBean   id= "counter "   scope= "request "   class= "Counter ">
</jsp:useBean>
<html>
<head>
<title> 出错演示 </title>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
</head>
<body>
</body>
</html>
javabean文件:-----------
//counter.java   读写文件的一个bean
import   java.io.*;

public   class   counter   extends   object   {
private   string   currentrecord   =   null;//保存文本的变量
private   bufferedreader   file;   //bufferedreader对象,用于读取文件数据
private   string   path;//文件完整路径名
public   counter()   {
}
//readfile方法用来读取文件filepath中的数据,并返回这个数据
public   string   readfile(string   filepath)   throws   filenotfoundexception
{
path   =   filepath;
//创建新的bufferedreader对象
file   =   new   bufferedreader(new   filereader(path));
string   returnstr   =null;
try
{
//读取一行数据并保存到currentrecord变量中
currentrecord   =   file.readline();
}
catch   (ioexception   e)
{//错误处理
system.out.println( "读取数据错误. ");
}
if   (currentrecord   ==   null)
//如果文件为空
returnstr   =   "没有任何记录 ";
else
{//文件不为空
returnstr   =currentrecord;
}
//返回读取文件的数据
return   returnstr;
}
//readfile方法用来将数据counter+1后写入到文本文件filepath中
//以实现计数增长的功能
public   void   writefile(string   filepath,string   counter)   throws  

filenotfoundexception
{
path   =   filepath;
//将counter转换为int类型并加一
int   writestr   =   integer.parseint(counter)+1;
try   {
//创建printwriter对象,用于写入数据到文件中
printwriter   pw   =   new   printwriter(new   fileoutputstream(filepath));
//用文本格式打印整数writestr
pw.println(writestr);
//清除printwriter对象
pw.close();
}   catch(ioexception   e)   {
//错误处理
system.out.println( "写入文件错误 "+e.getmessage());
}
}
}


最后报错的内容是:--------
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   3   in   the   jsp   file:   /test.jsp

Generated   servlet   error:
        [javac]   Compiling   1   source   file

D:\server\Tomcat\work\Catalina\localhost\jsq\org\apache\jsp\test_jsp.java:42:   cannot   resolve   symbol
symbol     :   class   Counter  
location:   class   org.apache.jsp.test_jsp
            Counter   counter   =   null;
            ^


An   error