• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about JavaBean?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Richard Phen
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried that way. It still doesn't work. I am using jswdk-1.0.1.
Why? Weird.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a statement somewhere that imports the Counter package?
Bill
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic