【问题标题】:How do I compare if a string is not equal to?如果字符串不等于,如何比较?
【发布时间】:2024-01-06 15:58:01
【问题描述】:

我试图仅根据字符串是否不等于来显示一些内容:

<c:if test="${content.getContentType().getName() != "MCE"}">
<li><a href="#publish-history" id="publishHistoryTab">Publish History</a></li>
</c:if>

它一直抛出错误org.apache.jasper.JasperException: /WEB-INF/jsp/content/manage.jsp(14,60) PWC6212: equal symbol expected

我也试过not eq而不是!=

not equal to 的有效语法是什么?

【问题讨论】:

  • 尝试“${not (content.getContentType().getName() eq 'MCE')}”。还要注意你使用的引号,因为上面的表达是不正确的。

标签: java jsp jstl


【解决方案1】:

Either != or ne will work,但您需要整理一下accessor syntax and nested quotes

<c:if test="${content.contentType.name ne 'MCE'}">
    <%-- snip --%>
</c:if>

【讨论】:

  • 有效,但 Eclipse 在令牌“ne”上返回语法错误,AssignmentOperator 无效
最近更新 更多