JSP and EL: EL Expression Examples : EL « JSP « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » JSP » EL 




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.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/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 ${2apples on the table.</b><br/>
<b>There are 
<fmt:formatNumber pattern="#####"> ${2}</fmt:formatNumber>
apples on the table.</b><br/>


<b>It feels like ${-8degree 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/54remaining. </b><br/>
<b>There are ${div 2apples on the table.</b><br/>
<b>There are ${2003 div 8apples on the table.</b><br/>
<b>There are ${2003 mod 8apples on the table.</b><br/>
<b>There are ${2003 8apples 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>

'3'   ${'3'}<br/>
'4' 3   ${'4' 3}<br/>
'4' '3' ${'4' '3'<br/>
>= 3    ${>= 3}<br/>
<= 3     ${3}<br/>
== '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>


           
       














BeginningJavaServerPages-ch05-1.zip( 291 k)
Related examples in the same category
1.EL and Complex JavaBeans
2.EL and Complex JavaBeans 1
3.EL Arithmetic
4.JSP and EL: EL Type Conversion Examples
5.JSP and EL:EL Property Access and Nested Properties
6.JSP and EL: Implicit Object Example Form processorJSP and EL: Implicit Object Example Form processor
7.EL Function Examples
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.