【发布时间】:2016-10-05 09:27:19
【问题描述】:
我们正在使用 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
任何cmets?!
【问题讨论】:
标签: java struts2 ognl valuestack