I used a JavaBean to read and write a txt file named count to record the amount of visiter. I compile and run this javaBean well at Command Prompt, but I encountered a error that shows cannot find method setCount() when I use it in jsp page. Why?
Could you help me fix it?
code of 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();
}*/
}
code in jsp:
<jsp:useBean id="MyCount" scope="session" class="Counter.Count"/>
<% MyCount.setCount();%>
Thanks a lot!!!