ChatGPT解决这个技术问题 Extra ChatGPT

如果字符串不等于,如何比较?

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

<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')}”。还要注意你使用的引号,因为上面的表达式是不正确的。

M
Matt Ball

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

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

可以工作,但 Eclipse 在令牌“ne”上返回语法错误,AssignmentOperator 无效