Should I choose == or eq for comparing string in EL?

≯℡__Kan透↙ 提交于 2019-11-30 00:20:12

They're both the same. I use eq in EL as it is more readable like a sentence.

Both are same. Both == and eq will result in the following code:

jspContext.findAttribute("person.sokande_i").equals("endast_usa")

for EL

${person.sokande_i == 'endast_usa'}

According to documentation, it's the same thing

In addition to the . and [] operators discussed in Value and Method Expressions, the EL provides the following operators, which can be used in rvalue expressions only:
[...]
Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values or against Boolean, string, integer, or floating-point literals.

One difference though : string operators like eq, ne, lt, gt, ge, le exist as they are XML safe, they would not need to be escaped like <= for instance.

It's explained here

A useful feature of the EL is the ability to perform comparisons, either between numbers or objects. This feature is used primarily for the values of custom tag attributes, but can equally be used to write out the result of a comparison (true or false) to the JSP page. The EL provides the following comparison operators:

• == or eq
• != or ne
• < or lt
• > or gt
• <= or le
• >= or ge

The second version of each operator exists to avoid having to use entity references in JSP XML syntax; however, the behavior of the operators is the same.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!