在学习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.