我把我的bean改为: package mybeans; import java.io.*; public class Counter implements Serializable { public int count; public Counter() { count=0; } public void setCount(int count) { this.count=count; } public int getCount(int count) { this.count=++count; return this.count; } } 重新编译后,我的jsp页面还是和从前一样不能显示,错误信息也一样
你好像没有给getCount传参数阿! jsp中加两句:<jsp:setProperty name="sessionBean" property="count"/> <jsp:setProperty name="applicationBean" property="count"/>方法getCount()改为: public int getCount() { this.count=++this.count; return this.count; } 感觉应该这样,没有试过,不一定对,仅作参考!
方法getCount()改为: public int getCount() { return (++count); } 但是每次提交后得到的结果是一样的,因为你用的事class="mybeans.Count". 用class的结果是,每次动态生成一个formbean的对象,没有达到计数的功能。
{
this.count=++count;
}
有问题,应该返回int吧:public int getCount()
{
return this.count;
}
{
this.count=++count;
}
有问题,应该返回int吧:public int getCount()
{
return this.count;
}
再说getCount()方法也应该有返回值呀
package mybeans;
import java.io.*;
public class Counter implements Serializable
{
public int count;
public Counter()
{
count=0;
}
public void setCount(int count)
{
this.count=count;
}
public int getCount(int count)
{
this.count=++count;
return this.count;
}
}
重新编译后,我的jsp页面还是和从前一样不能显示,错误信息也一样
jsp中加两句:<jsp:setProperty name="sessionBean" property="count"/> <jsp:setProperty name="applicationBean" property="count"/>方法getCount()改为:
public int getCount()
{
this.count=++this.count;
return this.count;
}
感觉应该这样,没有试过,不一定对,仅作参考!
public int getCount() {
return (++count);
}
但是每次提交后得到的结果是一样的,因为你用的事class="mybeans.Count".
用class的结果是,每次动态生成一个formbean的对象,没有达到计数的功能。