Expression Examples in Static Text

This section provides a tutorial example with different Rvalue expressions embedded in static text: literal data, variables, implicit objects, user defined objects, collection elements, object properties, nested properties.

To check my understanding of the expression language, I wrote the following JSP to show some expression examples embedded in static text:

<?xml version="1.0"?>
<jsp:root xmlns:jsp="" 
   xmlns:c="" version="2.1"> 
<!-- ExpExample.jspx
 - Copyright (c) 2012,, All Rights Reserved.
< contentType="text/html"/>
EL Expression in Static Text Examples:

1. ${1+1==2}
2. ${1+1}
3. ${1/3}
4. ${1.0/3.0}
5. ${quantity*price lt 100.0 and country=='USA'}
<c:set var="message" value="Hi there!"/>
6. ${message}
7. ${'message'}
10. ${pageContext.request.method}
11. ${pageContext.request[method]}
12. ${pageContext.request['method']}
<!-- 13. ${pageContext.request.'method'} -->
<!-- 14. ${pageContext.'request'.method} -->
15. ${pageContext['request']['method']}
16. ${pageContext['request'].method}
<!-- 20. ${pageContext.request.cookies.length} -->
21. ${pageContext.request.cookies[0].name}
22. ${pageContext.request.cookies[0].value}
23. ${pageContext.request.cookies[0]}
<!-- 24. ${pageContext.request.cookies.0} -->
<!-- 25. ${} -->
26. ${pageContext.request.cookies['0']}
<jsp:scriptlet>double pi = 3.14159;</jsp:scriptlet>
30. ${pi}
   double[] list = new double[3];
   list[0] = 9.99;
31. ${list[0]}
<!-- 32. ${} -->
<!-- 33. ${pageContext[request[class[name]]]} -->
34. ${empty out}
35. ${empty pageContext.out}
36. ${empty}
   session.setAttribute("now", new java.util.Date()); 
37. ${}

The output of this example JSP is presented in the next section. But before reading the output, I want you take a guess on resulting values of my expression examples and compare them with the output.

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

EL (Expression Language)

 What is EL (Expression Language)?

 EL Expression Types and Usage

 Literal Data and Named Variables

 Basic Operators and Operations

 Predefined Implicit Objects

 Collection Elements and Object Properties

Expression Examples in Static Text

 Expression Examples in Static Text - Result

 EL Variables Are pageContext Attributes

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials


 PDF Printing Version