Session 6 : el - Giáo trình Bách Khoa Aptech
-
Upload
hoc-lap-trinh-web -
Category
Technology
-
view
1.092 -
download
5
description
Transcript of Session 6 : el - Giáo trình Bách Khoa Aptech
![Page 1: Session 6 : el - Giáo trình Bách Khoa Aptech](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/1.jpg)
Slide 1 of 19
Expression Language
![Page 2: Session 6 : el - Giáo trình Bách Khoa Aptech](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/5.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/7.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/10.jpg)
Slide 10 of 19
EL Arithmetic Operators
![Page 11: Session 6 : el - Giáo trình Bách Khoa Aptech](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/11.jpg)
Slide 11 of 19
EL Relational Operators
![Page 12: Session 6 : el - Giáo trình Bách Khoa Aptech](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/12.jpg)
Slide 12 of 19
EL Logical Operators
![Page 13: Session 6 : el - Giáo trình Bách Khoa Aptech](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/13.jpg)
Slide 13 of 19
EL Empty Operators
![Page 14: Session 6 : el - Giáo trình Bách Khoa Aptech](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/15.jpg)
Slide 15 of 19
Define static method
![Page 16: Session 6 : el - Giáo trình Bách Khoa Aptech](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/17.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/18.jpg)
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](https://reader036.fdocuments.in/reader036/viewer/2022062319/554200d0550346531e8b45b8/html5/thumbnails/19.jpg)
Slide 19 of 19
Summary
Expression Language– ${EL Expression}
EL Features Variable / Attribute Implicit Objects