在Struts2中使用OGNL访问静态变量 [英] Accessing static variable using OGNL in Struts2
本文介绍了在Struts2中使用OGNL访问静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天!
我正在阅读Manning的struts2一书,其中一个主题是使用OGNL使用语法 @ [来访问静态变量fullClassName] @ [property或methodCall]
I am reading Manning's struts2 book and one of the topic is accessing the static variable using OGNL using the syntax @[fullClassName]@[property or methodCall]
所以我在我的程序上尝试了它,我的代码如下:
so I tried it on my program and my code is as follows:
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
但它不起作用。我错过了什么吗?
谢谢。
but it doesn't work. Am i missing something? Thank you.
推荐答案
@see OGNL基础知识:访问静态属性
@see OGNL Basics : Accessing static properties
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" />
这篇关于在Struts2中使用OGNL访问静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文