Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare if a string is not equal to?

Tags:

java

jsp

jstl

I'm trying to only show something based on if a string is not equal to:

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

It keeps throwing the error org.apache.jasper.JasperException: /WEB-INF/jsp/content/manage.jsp(14,60) PWC6212: equal symbol expected

I've also tried not eq instead of !=

What is the valid syntax for not equal to?

like image 592
Webnet Avatar asked Aug 27 '12 14:08

Webnet


People also ask

Can you use != For strings?

Note: When comparing two strings in java, we should not use the == or != operators. These operators actually test references, and since multiple String objects can represent the same String, this is liable to give the wrong answer.

How do you use not equal in if condition?

The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .

How say does not equal in a string?

You can use "!= " and "is not" for not equal operation in Python. The python != ( not equal operator ) return True, if the values of the two Python operands given on each side of the operator are not equal, otherwise false .

Can you compare strings with ==?

You should not use == (equality operator) to compare these strings because they compare the reference of the string, i.e. whether they are the same object or not. On the other hand, equals() method compares whether the value of the strings is equal, and not the object itself.


1 Answers

Either != or ne will work, but you need to get the accessor syntax and nested quotes sorted out.

<c:if test="${content.contentType.name ne 'MCE'}">     <%-- snip --%> </c:if> 
like image 168
Matt Ball Avatar answered Sep 28 '22 05:09

Matt Ball