为什么老说我找不到这个Method? JSP中的javabean应用。
我写了个javabean,用来读写一个count.txt文件,以达到记数的目的。编译和用main方法测试都通过,可以读写count.txt,并记数。可是把它放在jsp中测试时老说找不到setCount()方法,为什么?高手帮我看看!
javabean代码:
package Counter;
import java.io.*;
public class Count
{
private BufferedReader test;
private String tmp = null;
private int i =0;
private PrintWriter outf;
private File file;
public Count()
{
file = new File(".\\count.txt");
}
public void setCount()
{
try
{
test = new BufferedReader(new FileReader(file));
tmp = test.readLine();
}
catch(IOException e)
{
System.out.println("error");
}
if(tmp==null)
{
i=0;
}
else
{
i=Integer.parseInt(tmp)+1;
}
try
{
outf = new PrintWriter(new FileOutputStream(file));
outf.println(i);
outf.close();
test.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
/**public static void main(String[] args)
{
Count c = new Count();
c.doCount();
}*/
}
jsp中的代码:
<jsp:useBean id="MyCount" scope="session" class="Counter.Count"/>
<% MyCount.setCount();%>
错误提示:
com.sun.jsp.JspException: Compilation failed:Note: sun.tools.javac.Main has been
deprecated.
work\%3A8000%2Fcandysoft\index_jsp_1.java:94: Method setCount() not found in class Counter.Count.
MyCount.setCount();