引用自:https://www.cnblogs.com/ends-earth/p/10714068.html
jsp中需要引入ognl标签库才能用
<%@ taglib uri="/struts-tags" prefix=“s” %>
1)访问对象中的方法
<%@taglib uri ="/struts-tags" prefix="s"%>
2.访问静态方法
struts2中默认静态访问方法是关闭的(默认设置在struts2-core-xxx.jar 包中的 /org/apache/struts2---->default.properties文件中,内容如下)
### Whether to allow static method access in OGNL expressions or not
struts.ognl.allowStaticMethodAccess=false
所以首先需要在struts-xxx.xml中添加如下配置:
<struts>
<!-- 开启静态方法访问常量 -->
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
</struts>
<!-- 类的静态常量的访问 -->
PI = <s:property value = "@java.lang.Math@PI"/><br>
<!-- 需要设置 struts.ognl.allowStaticMethodAccess = true,才可以直接使用类的静态方法 -->
random = <s:property value = "@java.lang.Math@random() * 100"/><br>