Java/JSP/EL
Версия от 18:01, 31 мая 2010; (обсуждение)
Содержание
EL and Complex JavaBeans
<jsp:useBean id="person" class="com.jexp.Person" scope="request" />
<html>
<body>
<h1>EL and Complex JavaBeans</h1>
<table border="1">
<tr>
<td>${person.name}</td>
<td>${person.age}</td>
<td>${person["address"].line1}</td>
<td>${person["address"].town}</td>
<td>${person.address.phoneNumbers[0].std} ${person.address.phoneNumbers[0].number}</td>
<td>${person.address.phoneNumbers[1].std} ${person.address.phoneNumbers[1].number}</td>
</tr>
</table>
</body>
</html>
EL and Complex JavaBeans 1
<jsp:useBean id="person" class="com.jexp.Person" scope="request" />
<html>
<body>
<h1>EL and Complex JavaBeans</h1>
<table border="1">
<tr>
<td>${person.name}</td>
<td>${person.age}</td>
<td>${person["address"].line1}</td>
<td>${person["address"].town}</td>
<td>${person.address.phoneNumbers[0].std} ${person.address.phoneNumbers[0].number}</td>
<td>${person.address.phoneNumbers[1].std} ${person.address.phoneNumbers[1].number}</td>
</tr>
</table>
</body>
</html>
EL Arithmetic
<html>
<body>
<h1>EL Arithmetic</h1>
<table border="1">
<tr>
<td><b>Concept</b></td>
<td><b>EL Expression</b></td>
<td><b>Result</b></td>
</tr>
<tr>
<td>Literal</td>
<td>${"${"}10}</td>
<td>${10}</td>
</tr>
<tr>
<td>Addition</td>
<td>${"${"}10 + 10 }</td>
<td>${10 + 10}</td>
</tr>
<tr>
<td>Subtraction</td>
<td>${"${"}10 - 10 }</td>
<td>${10 - 10}</td>
</tr>
<tr>
<td>Multiplication</td>
<td>${"${"}10 * 10 }</td>
<td>${10 * 10}</td>
</tr>
<tr>
<td>Division / </td>
<td>${"${"}10 / 3 }</td>
<td>${10 / 3}</td>
</tr>
<tr>
<td>Division DIV</td>
<td>${"${"}10 div 3 }</td>
<td>${10 div 3}</td>
</tr>
<tr>
<td>Modulus</td>
<td>${"${"}10 % 10 }</td>
<td>${10 % 3}</td>
</tr>
<tr>
<td>Modulus</td>
<td>${"${"}10 mod 10 }</td>
<td>${10 mod 3}</td>
</tr>
<tr>
<td>Division by Zero</td>
<td>${"${"}10 / 0 }</td>
<td>${10 / 0}</td>
</tr>
<tr>
<td>Exponential</td>
<td>${"${"}2E2}</td>
<td>${2E2}</td>
</tr>
<tr>
<td>Unary Minus</td>
<td>${"${"}-10}</td>
<td>${-10}</td>
</tr>
</table>
</body>
</html>
EL Function Examples
/*
Beginning JavaServer Pages
Vivek Chopra, Jon Eaves, Rupert Jones, Sing Li, John T. Bell
ISBN: 0-7645-7485-X
*/
JSP and EL: EL Expression Examples
/*
Beginning JavaServer Pages
Vivek Chopra, Jon Eaves, Rupert Jones, Sing Li, John T. Bell
ISBN: 0-7645-7485-X
*/
<%@ taglib prefix="c" uri="http://java.sun.ru/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.ru/jsp/jstl/fmt" %>
<%@ taglib prefix="wroxtags" tagdir="/WEB-INF/tags" %>
<html>
<head>
<title>EL Expression Examples</title>
</head>
<body>
<h1>EL Expression Examples</h1>
<h2>Arithmetic Operators in Expressions</h2>
<c:set var="appleCount" value="${1 + 2 * 4 - 6 / 2}"/>
<b>There are ${1 + 2 * 4 - 6 / 2} apples on the table.</b><br/>
<b>There are
<fmt:formatNumber pattern="#####"> ${1 + 2 * 4 - 6 / 2}</fmt:formatNumber>
apples on the table.</b><br/>
<b>It feels like ${-4 - 8} degree today.</b><br/>
<c:set var="myGrade" value="11"/><br/>
<b>The average grade is ${(myGrade == 10) ? "perfect" : "good"}. </b><br/>
<b>There are ${23/54} remaining. </b><br/>
<b>There are ${6 div 2} apples on the table.</b><br/>
<b>There are ${2003 div 8} apples on the table.</b><br/>
<b>There are ${2003 mod 8} apples on the table.</b><br/>
<b>There are ${2003 % 8} apples on the table.</b><br/>
<h2>Logical Operators</h2>
<c:set var="guess" value="12"/>
<b>Your guess is ${guess}.</b><br/>
<c:if test="${(guess >= 10) && (guess <= 20)}">
<b>You"re in range!</b><br/>
</c:if>
<c:if test="${(guess < 10) || (guess > 20)}">
<b>Try again!</b><br/>
</c:if>
<c:set var="guess" value="1"/>
<b>Your guess is ${guess}.</b><br/>
<c:if test="${(guess >= 10) and (guess <= 20)}">
<b>You"re in range!</b><br/>
</c:if>
<c:if test="${(guess < 10) or (guess > 20)}">
<b>Try again!</b><br/>
</c:if>
<h2>Comparison Operators</h2>
4 > "3" ${4 > "3"}<br/>
"4" > 3 ${"4" > 3}<br/>
"4" > "3" ${"4" > "3"} <br/>
4 >= 3 ${4 >= 3}<br/>
4 <= 3 ${4 < 3}<br/>
4 == "4" ${4 == 4}<br/>
<h2>empty Operator</h2>
empty "" ${empty ""}<br/>
empty "sometext" ${empty "sometext"}<br/>
empty Junk ${empty Junk}<br/>
empty guess ${empty guess}<br/>
<h2>Boolean and Null Values</h2>
<c:set var="StrVar" value="true"/>
<c:if test="${StrVar}">
equal!
</c:if><br/>
null == null ${null == null}<br/>
"null" == null ${"null" == null}<br/>
</body>
</html>
JSP and EL:EL Property Access and Nested Properties
/*
Beginning JavaServer Pages
Vivek Chopra, Jon Eaves, Rupert Jones, Sing Li, John T. Bell
ISBN: 0-7645-7485-X
*/
JSP and EL: EL Type Conversion Examples
/*
Beginning JavaServer Pages
Vivek Chopra, Jon Eaves, Rupert Jones, Sing Li, John T. Bell
ISBN: 0-7645-7485-X
*/
JSP and EL: Implicit Object Example Form processor
/*
Beginning JavaServer Pages
Vivek Chopra, Jon Eaves, Rupert Jones, Sing Li, John T. Bell
ISBN: 0-7645-7485-X
*/