If-then-else inside a JSP expression?
问题 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. 回答1: 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