课外天地 李树青学习天地JavaEE网站开发课件 → 一个EL的练习


  共有14268人关注过本帖树形打印复制链接

主题:一个EL的练习

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1939 积分:26594 威望:0 精华:34 注册:2003/12/30 16:34:32
一个EL的练习  发帖心情 Post By:2009/5/6 22:52:11 [只看该作者]

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<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="00000"> ${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>

注意:
<fmt:formatNumber pattern="#####"> ${1 + 2 * 4 - 6 / 2}</fmt:formatNumber>可以去除小数点

[此贴子已经被作者于2010-12-12 11:01:07编辑过]

 回到顶部