Struts使用property标签取不到值的有趣的现象

来源:互联网 发布:智能家居软件系统 编辑:程序博客网 时间:2024/05/08 13:18

在使用Struts2的property标签时,记得属性value值得get方法不要设置成static, set方法最好也不要设置成static。get方法设置成static,那么变成了类方法,而Struts2是通过Action的实例来调用方法,所以类方法调用不了,就获取不了值了。

private static int helloCount=0;...public static void setHelloCount(int helloCount) {        HelloAction.helloCount = helloCount;    }    public static int getHelloCount() {        return helloCount;    }
第<s:property value="helloCount"  />次提交表单

上面给出的示例是获取不到helloCount的值,把get方法static修饰符去掉就可以了。

0 0
原创粉丝点击