在學習struts2框架的OGNL表達式時,訪問類的靜態方法獲取結果並在頁面上進行展示時,能夠展示該類的靜態變量,卻無法展示該類的靜態方法。
解決方法如下:
在struts.xml文件中添加如下語句:
- <constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
此時的struts.xml文件如下:
<struts>
<package name = "Pages" namespace="/Pages" extends = "struts-default">
<action name = "addLeague" class="controller.AddLeagueAction">
<result name = "success">addLeagueSucc.jsp</result>
<result name = "input">addLeague.jsp</result>
</action>
</package>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
</struts>
此時在jsp頁面中使用標籤語言訪問方法:
<s:property value = "@java.lang.Math@floor(12.34)" />
刷新頁面後,則能顯示值爲12.