el表达式之operators的应用



el表达式之operators的应用实例讲解。

el_operators.jsp文件:

<%@ page language=”java” import=”java.util.*” pageEncoding=”utf-8″%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>My JSP ‘el_operators.jsp’ starting page</title>
</head>
<body>
<table border=”1″>
<thead>
<td><b>EL表达式</b></td>
<td><b>运算符运算结果</b></td>
<td><b>EL表达式</b></td>
<td><b>运算符运算结果</b></td>
</thead>
<tr>
<td>\${11 }</td>
<td>${11 }</td>
<td>\${11+2 }</td>
<td>${ 11+2}</td>
</tr>
<tr>
<td>\${ 5.5+1.2}</td>
<td>${5.5+1.2 }</td>
<td>\${5*5 }</td>
<td>${5*5 }</td>
</tr>
<tr>
<td>\${ 2-1}</td>
<td>${2-1 }</td>
<td>\${2/1 }</td>
<td>${ 2/1}</td>
</tr>
<tr>
<td>\${2*2 }</td>
<td>${2*2 }</td>
<td>\${ 2%2}</td>
<td>${ 2%2}</td>
</tr>
<tr>
<td>\${2==2?2:0 }</td>
<td>${2==2?2:0 }</td>
<td>\${1<2?1:0 }</td>
<td>${1<2?1:0 }</td>
</tr>
</table>
</body>
</html>

EL Operators

<%– div and mod are alternatives to / and % –%>

Arithmetic Operators Relational Operators
Expression Result Expression Result
\${3+2-1} ${3+2-1} <%– Addition/Subtraction –%> \${1<2} ${1<2} <%– Numerical comparison –%>
\${“1″+2} ${“1″+2} <%– String conversion –%> \${“a”<”b”} ${“a”<”b”} <%– Lexical comparison –%>
\${1 + 2*3 + 3/4} ${1 + 2*3 + 3/4} <%– Mult/Div –%> \${2/3 >= 3/2} ${2/3 >= 3/2} <%– >= –%>
\${3%2} ${3%2} <%– Modulo –%> \${3/4 == 0.75} ${3/4 == 0.75} <%– Numeric = –%>
\${(8 div 2) mod 3} ${(8 div 2) mod 3} <%– Compares with “equals” but returns false for null –%> \${null == “test”} ${null == “test”}
Logical Operators empty Operator
Expression Result Expression Result
\${(1<2) && (4<3)} ${(1<2) && (4<3)} <%–AND–%> \${empty “”} ${empty “”} <%– Empty string –%>
\${(1<2) || (4<3)} ${(1<2) || (4<3)} <%–OR–%> \${empty null} ${empty null} <%– null –%>
\${!(1<2)} ${!(1<2)} <%– NOT -%> <%– Handles null or empty string in request param –%> \${empty param.blah} ${empty param.blah}