gpt4 book ai didi

java - Struts 2 中的 Lambda 表达式

转载 作者:行者123 更新时间:2023-11-29 05:23:04 24 4
gpt4 key购买 nike

我仍在使用 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]}",它会起作用。

最佳答案

由于安全漏洞,自 2.3.14.1 起默认禁用 OGNL 表达式的计算(有关详细信息,请参阅 S2-013)。

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

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

不推荐

改为使用:

<s:property value="#attr[some_var]"/>

关于java - Struts 2 中的 Lambda 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23893486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com