在学习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.
本文介绍如何在Struts2框架中通过OGNL表达式访问类的静态方法。通过配置允许静态方法访问,并给出具体示例,如使用Java的Math.floor()方法。
695

被折叠的 条评论
为什么被折叠?



