为什么老说我找不到这个Method? JSP中的javabean应用。

Netrich 2002-11-11 11:11:03
我写了个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();

...全文
168 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
yerongbiao 2002-12-17
  • 打赏
  • 举报
回复
我试了没问题!!
knoppix 2002-12-12
  • 打赏
  • 举报
回复
将你的包放到 WEB-INF/lib 了吗?
或者将 class 放到 WEB-INF/classes 目录下也行,但要注意按照包名放。
wushunhui 2002-12-12
  • 打赏
  • 举报
回复
我也出现了类似的问题啊,大虾救命啊!!!!!!
xmvigour 2002-11-14
  • 打赏
  • 举报
回复
也许javaeban对set和get的方法都进行规则设计
所以你如果有setXXXX 你最好在你的javabean里有对应的xxxx成员变量!
setCount()不行 你加个int count类成员变量在你的类中!
然后试试看
如果不想这样把setCount()改成IsetCount()看看!
Netrich 2002-11-14
  • 打赏
  • 举报
回复
是很奇怪,百思不得其解,大虾快来呀,要死人啦!
rateng 2002-11-14
  • 打赏
  • 举报
回复
我在jbuilder下也有这样的情况发现,在编译程序时没有说方法没有,而是在运行的时候去说没有发现方法的错误。奇怪了。。。???
Netrich 2002-11-14
  • 打赏
  • 举报
回复
我把int i改成num,把方法名改成setNum();还不行!

急死我也!
Netrich 2002-11-13
  • 打赏
  • 举报
回复
还是不行!怎么办呢?
松耦合紧内聚 2002-11-13
  • 打赏
  • 举报
回复
在jsp页面里加入
<%@ page import = "Counter.Count"%>
try again
Netrich 2002-11-13
  • 打赏
  • 举报
回复
按照您的代码修改后,出现新错误:
com.sun.jsp.JspException: getProperty(MyCount): cant find method to read {1}
at com.sun.jsp.compiler.GetPropertyGenerator.generate(GetPropertyGenerat
or.java:84)

把<jsp:getProperty name="MyCount" property="is"/>去掉,还是:
work\%3A8000%2Fcandysoft\index_jsp_1.java:94: Method setNum() not found in class
Counter.Count.
MyCount.setNum();

我用的是jswdk-1.0.1。
zskllj 2002-11-13
  • 打赏
  • 举报
回复
可以呀!
zskllj 2002-11-13
  • 打赏
  • 举报
回复
jsp:
<%@page errorPage="/error.jsp"%>
<jsp:useBean id="MyCount" scope="session" class="untitled2.Count"/>
<%MyCount.setCount();%>
<jsp:getProperty name="MyCount" property="is"/>

bean:
package untitled2;

import java.io.*;

public class Count
{
private BufferedReader test;
private String tmp = null;
private int is =0;
private File file;

public Count()
{
file = new File("count.txt");
}
public void setCount()
{
try
{
test = new BufferedReader(new FileReader(file));
tmp = test.readLine();
test.close();
}catch(IOException e){
System.out.println("error");
}
if(tmp==null){
is=0;
}else{
is=Integer.parseInt(tmp)+1;
}
try
{
PrintWriter outf = new PrintWriter(new FileOutputStream(file));
outf.println(is);
outf.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
}

public String getIs(){
return new Integer(is).toString();
}
public void setIs(int s){
this.is=s;
}


/**public static void main(String[] args)
{
Count c = new Count();
c.doCount();
}*/

}
Netrich 2002-11-13
  • 打赏
  • 举报
回复
请说的详细点,javabean路径不对,应该是找不到类,而不会是找不到方法呀。
ldzhi 2002-11-13
  • 打赏
  • 举报
回复
是那个javabean的路径不对。
saidong 2002-11-11
  • 打赏
  • 举报
回复
删除这些编译过的文件,再编译试试。
work\%3A8000%2Fcandysoft\index_jsp_1.java
setCount()这个方法是不是后加的呀?不知是缓存还是什么原因,老出这样的问题。但一般重新编译后,重起server服务解决。有时甚至碰到需要删除已编译过的文件,并把jsp中,useBean和MyCount.setCount()重新写一遍。
Netrich 2002-11-11
  • 打赏
  • 举报
回复
是重新编译,web server也重启了,可还是不行!怎么办呢?
xmvigour 2002-11-11
  • 打赏
  • 举报
回复
改了重新编译 把web server重启一下
Netrich 2002-11-11
  • 打赏
  • 举报
回复
改了还是不行!这和名字有关系吗?
xmvigour 2002-11-11
  • 打赏
  • 举报
回复
setCount()改为其它名字 再试试!
Netrich 2002-11-11
  • 打赏
  • 举报
回复
都试了!还是不行!怎么办呢?

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧