3

我的 Struts 2 应用程序有问题。

我读取了数组迭代器的内容。

数组元素由迭代器写出:

<s:text name="#wApps.title"/>

标记找到正确的元素并对其求值,但结果表达式有一个+字符(例如:数组元素的值:"Weather+ Free"'),并且它继续对其求值。最后,它写出 value: nullnull

如何跳过第二次评估?

这是日志:

Jun 18, 2013 5:29:40 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: The first TextProvider in the ValueStack (rs.plusnet.android.market.AndroidMarket.UI.ListCategory) could not locate the message resource with key '**Weather+ Free**'
Jun 18, 2013 5:29:40 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: The default value expression 'Weather+ Free' evaluated to '**nullnull**'
4

1 回答 1

2

这不是struts,OGNL的问题。OGNL 不会计算表达式两次,没有包含子表达式的特殊语法。但是,如果您在没有配额的情况下输入表达式,“+”号是一个计算表达式的运算符。

用配额包围这样的值以防止评估。

<s:set var="title" value="'Weather+ Free'"/>

或像这样使用正文中的值

<s:set var="title">Weather+ Free</s:set>

检查它

<s:property value="#title"/>

此外,如果该值在 action 属性或任何其他范围内,则永远不应发生双重评估。

于 2013-06-18T11:02:56.593 回答