19
Slide 1 of 19 Expression Language

Session 6 : el - Giáo trình Bách Khoa Aptech

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 1 of 19

Expression Language

Page 2: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 2 of 19

Overview Expression Language EL Features Variable / Attribute Implicit Objects

Page 3: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 3 of 19

Script Expression

Any required value can be directly placed into the generated dynamic content using JSP expression

The expression is inserted into the JSP page after being evaluated and converted to string

Page 4: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 4 of 19

Expression Language New feature of JSP 2.0 Allows JSP developers to access java

objects via a compact, easy-to-use shorthand style

Developed by two groups– JSP Standard Tag Library expert group – JSP 2.0 expert group

Syntax– ${EL Expression}

JSP EL expressions are used in– Static text– Standard and Custom tags

Page 5: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 5 of 19

EL Features Key Features

– Easy syntax for accessing variables– Special support for collection objects and arrays– Implicit objects– Arithmetic

EL expressions can be disabled / enabled using isELIgnored attribute– <%@page isELIgnored=“true | false” %>

JSP EL Expressions are evaluated at runtime

Page 6: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 6 of 19

EL Expression with Prior JSP 2.0

By default JSP 1.2 or prior version ignore the EL Expression

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><jsp-config>

<jsp-property-group><url-pattern>*.jsp</url-pattern><el-ignored>false</el-ignored>

</jsp-property-group></jsp-config>

</web-app>

Page 7: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 7 of 19

Variable / Attribute Variables are used to store and access

values in JSP program Variable refers as a attributes that are

stored in standard scope such as page, request, session and application

Dot operator . or square brackets [ ] can be used to access value of variable– ${pageScope.color}– ${pageScope[“color”]}

Page 8: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 8 of 19

EL - Implicit Objects

Implicit Objects

pageContext cookieinitParamparamValuesparam

header headerValues

application

servletContext

request

session

response

Page 9: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 9 of 19

EL Operators

*

/ or div

+

-

% or mod

Operators

EmptyLogicalRelationalArithmetic

< or lt

> or gt

< = or le

> = or ge

= = or eq

!= or ne

&& or and

|| or or

! or not

empty

Page 10: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 10 of 19

EL Arithmetic Operators

Page 11: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 11 of 19

EL Relational Operators

Page 12: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 12 of 19

EL Logical Operators

Page 13: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 13 of 19

EL Empty Operators

Page 14: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 14 of 19

Call static method using EL

Static methods can be called within the EL expression

Step to call static methods using EL– Define static method– Regist with tag libray descriptor– Access EL functions within JSP

Page 15: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 15 of 19

Define static method

Page 16: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 16 of 19

Register with tag library descriptorDeclare the static function with the .tld file

Page 17: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 17 of 19

Access EL functions within JSPAccess the function using an EL expression

Page 18: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 18 of 19

Coercion

Converts parameters to the appropriate objects or primitives automatically

JSTL defines appropriate conversion with default values

Coercion

Boxing and Unboxing

Coercion to String

Coercion to Number

Page 19: Session 6 : el  - Giáo trình Bách Khoa Aptech

Slide 19 of 19

Summary

Expression Language– ${EL Expression}

EL Features Variable / Attribute Implicit Objects