JSP 2.0 Expression Language - Basic Arithmetic


This example illustrates basic Expression Language arithmetic. Addition (+), subtraction (-), multiplication (*), division (/ or div), and modulus (% or mod) are all supported. Error conditions, like division by zero, are handled gracefully.
EL Expression Result
\${1} ${1}
\${1 + 2} ${1 + 2}
\${1.2 + 2.3} ${1.2 + 2.3}
\${1.2E4 + 1.4} ${1.2E4 + 1.4}
\${-4 - 2} ${-4 - 2}
\${21 * 2} ${21 * 2}
\${3/4} ${3/4}
\${3 div 4} ${3 div 4}
\${3/0} ${3/0}
\${10%4} ${10%4}
\${10 mod 4} ${10 mod 4}
\${(1==2) ? 3 : 4} ${(1==2) ? 3 : 4}