Tag Archives: jsp

Ternary operators in JSP

Every now and then I come across things I haven’t used before but should have been using.  The ternary operator in JSP is one of them.

It makes it so much easier to write out some text based on a conditional without having to put it in a request attribute explicitly or do an if/then conditional with a possible set operation using the JSTL core library.


${booleanTest ? 'output if true' : 'output if false'}

This came in really handy for adding an additional css class to a div based on a condition in the JSP in this particular case.