if-then-else在一个JSP表达式中? [英] If-then-else inside a JSP expression?
本文介绍了if-then-else在一个JSP表达式中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编辑:具体来说,我正在寻找一个JSP解决方案,而不是JSTL解决方案。但下面的一些JSTL解决方案被高度评价,非常受欢迎。只需要给我一个重复的问题,因为已经有人问过JSTL。
解决方案
在JSP EL 2.0中,你可以使用三元运算符来做到这一点。例如:
< option value =1$ {param.number == 1? 'selected':''}>第一个选项< / option>
它的作用是检查JSP的 param
的号码
变量。如果是1,则选择被替换。否则,没有。
Can you do an if-then-else statement inside a JSP expression?
EDIT : Specifically I was looking for a JSP solution, not a JSTL solution. But some JSTL solutions below are highly rated and are very welcome. Just please do not vote me down for a duplicate question because one has already been asked about JSTL.
解决方案
In JSP EL 2.0, you can do that using the ternary operator. For instance:
<option value="1" ${param.number == 1 ? 'selected' : ''}>First option</option>
What it does is it checks JSP's param
's number
variable. If it's 1, then selected is substituted. otherwise, nothing.
这篇关于if-then-else在一个JSP表达式中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文