OGNL允许执行方法,但是默认情况下禁用静态访问,因此您不能在表达式中使用静态方法。但是,您可以教OGNL哪些类需要访问静态方法。
[OGNL开发人员指南:方法访问器](https://commons.apache.org/proper/commons-
ognl/developer-guide.html#Method_Accessors)
方法调用是OGNL需要基于动态信息对方法进行查找的另一个领域。该
MethodAccessor接口提供了有关OGNL如何调用方法的信息。当请求静态或实例方法时,将调用此接口的实现者以实际执行该方法。public interface MethodAccessor{ Object callStaticMethod( Map context, Class targetClass, StringmethodName, List args )
throws MethodFailedException;Object callMethod( Map context, Object target, String methodName,List args )
throws MethodFailedException;}您可以使用逐个类地设置方法访问器
OgnlRuntime.setMethodAccessor()。是Object的默认方法访问器(它仅根据方法名称和参数类型查找适当的方法,并使用反射来调用该方法)。
您可以编写一些东西
public class StringUtil extends StringUtils implements MethodAccessor { //implement above methods}动作课
public static final String MESSAGE = "hello.message";private String message;public String getMessage() { return message;}private StringUtil stringUtil = new StringUtil();public StringUtil getStringUtil() { return stringUtil;}public String execute() throws Exception { setMessage(getText(MESSAGE)); OgnlRuntime.setMethodAccessor(StringUtil.class, stringUtil); return SUCCESS;}在JSP中
<s:if test="!stringUtil.isEmpty(message)"> <h2><s:property value="message"/></h2></s:if>



