我们正在使用 Struts 2 验证器@FieldExpressionValidator
和@ExpressionValidator
. 这些验证器检查 OGNL 表达式。在很多情况下,我们在这些表达式中处理字符串。
expression="(captcha=='' && captcha== null || ....)
如果我们可以在这里使用 StringUtils ( isEmpty ,trimToEmpty,... ),我们会发现它非常有用。
当我们将其设置 struts.ognl.allowStaticMethodAccess
为 false 时,出于安全问题,我们尝试通过将此 getter 添加到操作中来解决它
public StringUtils getStringUtils(){
return new StringUtils();
}
然后stringUtils.isEmpty(captcha)
在表达式中。但它没有用。
为了调试我们测试了
ActionContext.getContext().getValueStack().findValue("stringUtils"); //returns org.apache.commons.lang3.StringUtils@693ade51 which shows there is an object in the stack
ActionContext.getContext().getValueStack().findValue("stringUtils.isEmpty('dd')"); //returns null
任何意见 ?!