且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在jstl中使用三元运算符编写if else条件

更新时间:2023-11-10 09:19:04

你的意思是表达语言,简称EL,因为那是允许的组件你使用 $ {something} 表达式,而JSTL是一个标签库,它为你提供标签组件,如< c:set>

You mean Expression Language, EL in short, since that's the component that allows you use ${something} expressions, while JSTL is a tag library which gives you tag components like <c:set>.

在EL中,你可以这样做:

In EL, you can do it like this:

<c:set var="ternaryResult"
    value="${(relAttributeValue != 'false') ? 'rel=\"nofollow\"' : ''}" />

请注意,在EL中,您无需担心使用比较引用== 就像在Java中一样。有关这方面的更多信息:在EE 6 JSF EL中是否有来自Java的'=='

Note that in EL you don't need to worry about comparing references using == like in Java. More info on this: Is there an equivalent of '==' from Java in EE 6 JSF EL