Struts 2中的Lambda表达式

时间:2014-05-27 15:34:18

标签: java jsp struts2 lambda ognl

我还在使用Struts 2.3.16。我绕过Struts2文档并试图在我的JSP页面上使用lambda表达式。但它不起作用。同样在我以前的答案中,我使用括号表达式来评估OGNL中的嵌套表达式。但它似乎不再起作用了。

这是lambda表达式不起作用

<s:property value="#fib =:[#this==0 ? 0 : #this==1 ? 1 : #fib(#this-2)+#fib(#this-1)], #fib(11)" />  

这是答案中带括号的表达式

<% String str27 = "hello27"; %>
<%ActionContext.getContext().getValueStack().set("str27", str27); //set to root %>
<s:property value="str27"/> <br>
<%ActionContext.getContext().getValueStack().getContext().put("str27", str27); //set to context %>
<s:property value="#str27"/> <br>
<s:set var="str28" value="'str27'"/>

str28: <s:property value="%{(#str28)(0)}"/><br>

我也知道如果我使用value="%{#attr[#str28]}"它会有效。

1 个答案:

答案 0 :(得分:3)

由于存在安全漏洞,默认情况下对{0}}的OGNL表达式的评估已被禁用(有关详细信息,请参阅S2-013)。

当然,您可以通过将2.3.14.1设置为struts.ognl.enableOGNLEvalExpression来启用评估。

true

不推荐

改为使用:

<constant name="struts.ognl.enableOGNLEvalExpression" value="true" />