美好的一天!
我正在阅读 Manning 的 struts2 书,其中一个主题是使用 OGNL 使用语法 @[fullClassName]@[property or methodCall] 访问静态变量
所以我在我的程序上尝试了一下,我的代码如下:
bean :
public class ContactsBean {
private static int count = 1;
//getter and setter
}
行动:
private ContactsBean contacts;
//getters and setters
JSP:
<s:property value="@com.demo.bean.ContactsBean@count" />
or
<s:property value="@vs@count" /> //valuestack method
但它不起作用。我错过了什么吗? 谢谢。
最佳答案
bean :
public class ContactsBean {
private static int count = 1;
// static getter
// setter
}
<s:property value="@com.demo.bean.ContactsBean@getCount()" />
<小时/>
其他情况
public class ContactsBean {
public static final int SCALE = 50;
}
<s:property value="@com.demo.bean.ContactsBean@SCALE" />
关于jakarta-ee - Struts2中使用OGNL访问静态变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6906629/