【问题标题】:Problems comparing strings within an iterator在迭代器中比较字符串的问题
【发布时间】:2013-07-30 16:15:00
【问题描述】:

在迭代器中比较字符串时遇到问题 JSP:

<s:iterator value="piecesTxt">
   <s:if test="top.equals('_')">
      <s:textfield name="solIntrod" theme="simple" size="2" maxlength="1"/>
   </s:if>
   <s:else>
      <s:property/>
   </s:else>
 </s:iterator>

piecesTxt 是一个包含以下内容的列表: - 文字片段。 - 间隙,存储在列表中的字符串“_”

JSP 将“_”显示为文本:

El ot _ o d _ a f _ imos a na _ egar en un _ ate.

我也尝试过:

<s:if test="top == '_'">
Including in s:iterator var="pt"
<s:if test="pt == '_'"> 
<s:if test="pt.top == '_'">
<s:if test="pt.charAt(0) == '_'">

其他迭代器文本有效,但这不起作用。有任何想法吗? 提前致谢。

【问题讨论】:

    标签: string jsp testing struts2 iterator


    【解决方案1】:

    OGNL 将单引号内的单个字符解释为 char,而不是 String

    使用双引号:

    <s:if test='top.equals("_")'>
    

    详情请见Why won't the 'if' tag evaluate a one char string

    【讨论】:

    • 有效!谢谢!我总是使用简单的 cuotes 并且也可以工作: 可能是因为字符串至少包含两个字符 (?)
    猜你喜欢
    • 2012-02-24
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 2011-06-03
    • 1970-01-01
    相关资源
    最近更新 更多