检查内容中是否存在值 - Struts2

Check if a value is present in a content - Struts2

如何检查 Struts2 中的 table 中是否存在某个值? 这就是它在 Struts1.

中的工作方式
  <logic:present name="<%=Globals.ERROR_KEY%>">
        <table class="table">
          <tr>
            <td class="name" color="red">
    </logic:present>
              <html:errors />
    <logic:present name="<%=Globals.ERROR_KEY%>">
         </td>
      </tr>
     </table>
</logic:present>

你可以使用一种方法hasActionErrors() of ActionSupport class that could be checked in JSP if you need to wrap some content around <s:actionerror/>。您的操作应该扩展 class.

Render action errors if they exists the specific layout of the rendering depends on the theme itself. Empty (null or blank string) errors will not be printed. The action error strings will be html escaped by default.


<logic:present> 相当于 Struts2 是

<s:if test="somekey != null && somekey != ''">

其中 somekey 是 valueStack 中的一个变量,具有 action 范围。 AFAIK logic:present 标签在所有范围内搜索,因此您可以向键添加 #attr 前缀。