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

    xiaoxiao2021-12-14  20

    在使用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修饰符去掉就可以了。

    转载请注明原文地址: https://ju.6miu.com/read-969463.html

    最新回复(0)