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

Post on 30-Apr-2015

1092 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

Transcript

Slide 1 of 19

Expression Language

Slide 2 of 19

Overview Expression Language EL Features Variable / Attribute Implicit Objects

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

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

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

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>

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”]}

Slide 8 of 19

EL - Implicit Objects

Implicit Objects

pageContext cookieinitParamparamValuesparam

header headerValues

application

servletContext

request

session

response

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

Slide 10 of 19

EL Arithmetic Operators

Slide 11 of 19

EL Relational Operators

Slide 12 of 19

EL Logical Operators

Slide 13 of 19

EL Empty Operators

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

Slide 15 of 19

Define static method

Slide 16 of 19

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

Slide 17 of 19

Access EL functions within JSPAccess the function using an EL expression

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

Slide 19 of 19

Summary

Expression Language– ${EL Expression}

EL Features Variable / Attribute Implicit Objects

top related