aspose file tools*
The moose likes JSP and the fly likes A question about JavaBean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "A question about JavaBean?" Watch "A question about JavaBean?" New topic
Author

A question about JavaBean?

Richard Phen
Ranch Hand

Joined: Apr 27, 2002
Posts: 52
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!!!


SCJP<br />SCJD
Jack Nicholson
Ranch Hand

Joined: Sep 07, 2002
Posts: 41
The Error may be like you have changed the class file & server may not be getting updated version of class file.
Do Stop Start for the server you are using.
If using Tomcat4.1 do -->
reloadable property to true in context path setting in server.xml file, so whenever your class file is updated it will automatically reloaded in server.
I hope this may be the problem...


Jack Nicholson
Richard Phen
Ranch Hand

Joined: Apr 27, 2002
Posts: 52
I have tried that way. It still doesn't work. I am using jswdk-1.0.1.
Why? Weird.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
Do you have a statement somewhere that imports the Counter package?
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A question about JavaBean?