SlideShare a Scribd company logo
1 of 17
Object persistence and EL
Agenda
• Persisting Object in Request, Session, Application Scope in
Servlet
• Understanding the implementation of EL
Introduction to EL
• EL was first introduced in JSTL 1.0
• EL is now incorporated in JSP 2.0
• Pattern that identifies expression language is ${}
• To deactivate the evaluation of EL specify the isELIgnore
attribute of page directive to true
Operators in EL
Operator Description
. Access abean property orMap entry.
[] Access an array orList element.
() Grouping of asubexpression forevaluation order.
? : Conditional test: condition ? ifTrue : ifFalse.
+ Addition.
- Subtraction.
* Multiplication.
/or div Division.
% or mod Modulo (remainder).
Operators in EL
Operator Description
== or eq equality.
!= or ne inequality.
< or lt less than.
> or gt greater than.
<= or le less than or equal.
>= or ge greater than or equal.
&& or and logical AND.
|| or or logical OR.
! or not Unary Boolean complement.
empty Test for null,empty String,array or Collection.
func(args) A function call.
Accessing Scoped Variable
• ${varName}
- Means to search the PageContext, the HttpServletRequest, the
HttpSession, and the ServletContext, in that order, and output
the object with that attribute name.
- PageContext does not apply with MVC.
• Equivalent forms
- ${name}
- <%= pageContext.findAttribute("name") %>
- <jsp:useBean id="name” type="somePackage.SomeClass”
scope="...“>
<%= name %>
Accessing Bean properties
• ${varName.propertyName}
- Means to find scoped variable of given name and output the
specified bean property
• Equivalent forms
- ${customer.firstName}
<%@ page import=“model.NameBean" %>
<% NameBean person =
(NameBean)pageContext.findAttribute("customer");
%>
<%= person.getFirstName() %>
Accessing Bean properties
• Equivalent forms
- ${customer.firstName}
- <jsp:useBean id="customer”
type="coreservlets.NameBean”
scope="request, session, or application" />
<jsp:getProperty name="customer” property="firstName" />
• This is better than script on previous slide.
- But, requires you to know the scope
- And fails for subproperties.
• No non-Java equivalent to ${customer.address.zipCode}
Accessing persisted value
• Scope Examples
• Accessing a page-scoped attribute named as firstName:
${pageScope.firstName}
• Accessing a request-scoped attribute named as firstName:
${requestScope.firstName}
• Accessing a session-scoped attribute named as 'lastName' (null if not
found): ${sessionScope.lastName}
• Page Context Examples
• ${pageContext.request.protocol} $
• {pageContext.response.locale}
• ${pageContext.session.id} ${pageContext.servletContext} Above we are
accessing request, response, session, and application properties, using the
pageContext implicit object.
Dot and array Notations
Equivalent forms
– ${name.property}
– ${name["property"]}
• Reasons for using array notation
– To access arrays, lists, and other collections
• See upcoming slides
– To calculate the property name at request time.
• {name1[name2]} (no quotes around name2)
– To use names that are illegal as Java variable names
• {foo["bar-baz"]}
• {foo["bar.baz"]}
Accessing Collections
• ${attributeName[entryName]}
Works for
- Array. Equivalent to theArray[index]
- List. Equivalent to theList.get(index)
- Map. Equivalent to theMap.get(keyName)
• Equivalent forms (for HashMap)
- ${stateCapitals["maryland"]}
- ${stateCapitals.maryland}
• But the following is illegal since 2 is not a legal var name
- ${listVar.2}
Reading Cookie using EL
• Cookie Example
• addCookies.java Cookie c=new Cookie("name","test");
• res.addCookie(c);
• Test.jsp
• Name : ${cookie["name"]}
• Value : ${cookie["name"].value}
• Here in addCookies.java we are creating a new Cookie,These values
can be retrieved in jsp by using ${cookie.xxxx}.
Using EL in custom tags
• EL expressions can be used:
- In static text
- In any standard or custom tag attribute that can accept
an expression
• The value of an expression in static text is computed and inserted into
the current output. If the static text appears in a tag body, note that an
expression will not be evaluated if the body is declared to be
tagdependent
Using EL in custom tags
• There are three ways to set a tag attribute value:
- With a single expression construct:
- <some:tag value="${expr}"/>
- The expression is evaluated and the result is coerced to the attribute's expected
type.
• With one or more expressions separated or surrounded by text:
- <some:tag value="some${expr}${expr}text${expr}"/>
- The expressions are evaluated from left to right. Each expression is coerced to a
String and then concatenated with any intervening text. The resulting String is then
coerced to the attribute's expected type.
• With text only:
- <some:tag value="sometext"/>
- In this case, the attribute's String value is coerced to the attribute's expected type.
Advantages of Expression language
• Concise access to stored objects.
- To output a “scoped variable” (object stored with setAttribute in the
PageContext, HttpServletRequest, HttpSession, or ServletContext) named
saleItem, you use ${saleItem}.
• Shorthand notation for bean properties.
- To output the companyName property (i.e., result of the getCompanyName
method) of a scoped variable named company, you use
${company.companyName}. To access the firstName property of the president
property of a scoped variable named company, you use
${company.president.firstName}.
• Simple access to collection elements.
- To access an element of an array, List, or Map, you use
${variable[indexOrKey]}. Provided that the index or key is in a form that is
legal for Java variable names, the dot notation for beans s interchangeable with
the bracket notation for collections.
Advantages of Expression language
• Succinct access to request parameters, cookies, and other request data.
- To access the standard types of request data, you can use one ofseveral
predefined implicit objects.
• A small but useful set of simple operators.
- To manipulate objects within EL expressions, you can use any of several
arithmetic, relational, logical, or empty-testing operators.
• Conditional output.
- To choose among output options, you do not have to resort to Java scripting
elements. Instead, you can use ${test ? option1 : option2}
• Automatic type conversion.
- The expression language removes the need for most typecasts and for much of
the code that parses strings as numbers.
• Empty values instead of error messages.
- In most cases, missing values or NullPointerExceptions result in empty strings,
not thrown exceptions.
Summary
• The JSP 2.0 EL provides concise, easy to read access to
- Bean properties
- Collection elements
- Standard HTTP elements such as request
parameters,request headers, and cookies
• The JSP 2.0 EL works best with MVC
- Use only to output values created by separate Java
code
• Resist use of EL for business logic

More Related Content

What's hot

Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterJAXLondon2014
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8IndicThreads
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5dplunkett
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2sumitbardhan
 
Oracle Course content
Oracle Course contentOracle Course content
Oracle Course contentTRINADH G
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhHarmeet Singh(Taara)
 
Erlang intro
Erlang introErlang intro
Erlang introSSA KPI
 
Project Lambda: To Multicore and Beyond
Project Lambda: To Multicore and BeyondProject Lambda: To Multicore and Beyond
Project Lambda: To Multicore and BeyondDmitry Buzdin
 

What's hot (20)

Week2 dq4
Week2 dq4Week2 dq4
Week2 dq4
 
JAVASCRIPT - LinkedIn
JAVASCRIPT - LinkedInJAVASCRIPT - LinkedIn
JAVASCRIPT - LinkedIn
 
X FILES
X FILESX FILES
X FILES
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Ocl
OclOcl
Ocl
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Lambdas
LambdasLambdas
Lambdas
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Hive
HiveHive
Hive
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
Oracle Course content
Oracle Course contentOracle Course content
Oracle Course content
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Erlang intro
Erlang introErlang intro
Erlang intro
 
Chapter3
Chapter3Chapter3
Chapter3
 
Project Lambda: To Multicore and Beyond
Project Lambda: To Multicore and BeyondProject Lambda: To Multicore and Beyond
Project Lambda: To Multicore and Beyond
 

Similar to Advance java session 14

Using the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 featuresUsing the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 featuresArun Gupta
 
Understanding
Understanding Understanding
Understanding Arun Gupta
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and OperatorsMarwa Ali Eissa
 
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 IndiaUsing the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 IndiaArun Gupta
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)mircodotta
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
Java Script
Java ScriptJava Script
Java ScriptSarvan15
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfSreeVani74
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
15 expression-language
15 expression-language15 expression-language
15 expression-languagesnopteck
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Baruch Sadogursky
 

Similar to Advance java session 14 (20)

Java script basics
Java script basicsJava script basics
Java script basics
 
Java beans
Java beansJava beans
Java beans
 
Typescript
TypescriptTypescript
Typescript
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Using the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 featuresUsing the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 features
 
Understanding
Understanding Understanding
Understanding
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 IndiaUsing the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 
Expression language
Expression languageExpression language
Expression language
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
15 expression-language
15 expression-language15 expression-language
15 expression-language
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
 

More from Smita B Kumar

Advance java session 20
Advance java session 20Advance java session 20
Advance java session 20Smita B Kumar
 
Advance java session 19
Advance java session 19Advance java session 19
Advance java session 19Smita B Kumar
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18Smita B Kumar
 
Advance java session 17
Advance java session 17Advance java session 17
Advance java session 17Smita B Kumar
 
Advance java session 16
Advance java session 16Advance java session 16
Advance java session 16Smita B Kumar
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15Smita B Kumar
 
Advance java session 13
Advance java session 13Advance java session 13
Advance java session 13Smita B Kumar
 
Advance java session 12
Advance java session 12Advance java session 12
Advance java session 12Smita B Kumar
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11Smita B Kumar
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10Smita B Kumar
 
Advance java session 9
Advance java session 9Advance java session 9
Advance java session 9Smita B Kumar
 
Advance java session 8
Advance java session 8Advance java session 8
Advance java session 8Smita B Kumar
 
Advance java session 7
Advance java session 7Advance java session 7
Advance java session 7Smita B Kumar
 
Advance java session 6
Advance java session 6Advance java session 6
Advance java session 6Smita B Kumar
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5Smita B Kumar
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4Smita B Kumar
 
Advance java session 3
Advance java session 3Advance java session 3
Advance java session 3Smita B Kumar
 
Advance java session 2
Advance java session 2Advance java session 2
Advance java session 2Smita B Kumar
 
01 introduction to struts2
01 introduction to struts201 introduction to struts2
01 introduction to struts2Smita B Kumar
 

More from Smita B Kumar (20)

Advance java session 20
Advance java session 20Advance java session 20
Advance java session 20
 
Advance java session 19
Advance java session 19Advance java session 19
Advance java session 19
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18
 
Advance java session 17
Advance java session 17Advance java session 17
Advance java session 17
 
Advance java session 16
Advance java session 16Advance java session 16
Advance java session 16
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15
 
Advance java session 13
Advance java session 13Advance java session 13
Advance java session 13
 
Advance java session 12
Advance java session 12Advance java session 12
Advance java session 12
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
 
Advance java session 9
Advance java session 9Advance java session 9
Advance java session 9
 
Advance java session 8
Advance java session 8Advance java session 8
Advance java session 8
 
Advance java session 7
Advance java session 7Advance java session 7
Advance java session 7
 
Advance java session 6
Advance java session 6Advance java session 6
Advance java session 6
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4
 
Advance java session 3
Advance java session 3Advance java session 3
Advance java session 3
 
Advance java session 2
Advance java session 2Advance java session 2
Advance java session 2
 
JEE session 1
JEE session 1JEE session 1
JEE session 1
 
01 introduction to struts2
01 introduction to struts201 introduction to struts2
01 introduction to struts2
 

Recently uploaded

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Recently uploaded (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

Advance java session 14

  • 2. Agenda • Persisting Object in Request, Session, Application Scope in Servlet • Understanding the implementation of EL
  • 3. Introduction to EL • EL was first introduced in JSTL 1.0 • EL is now incorporated in JSP 2.0 • Pattern that identifies expression language is ${} • To deactivate the evaluation of EL specify the isELIgnore attribute of page directive to true
  • 4. Operators in EL Operator Description . Access abean property orMap entry. [] Access an array orList element. () Grouping of asubexpression forevaluation order. ? : Conditional test: condition ? ifTrue : ifFalse. + Addition. - Subtraction. * Multiplication. /or div Division. % or mod Modulo (remainder).
  • 5. Operators in EL Operator Description == or eq equality. != or ne inequality. < or lt less than. > or gt greater than. <= or le less than or equal. >= or ge greater than or equal. && or and logical AND. || or or logical OR. ! or not Unary Boolean complement. empty Test for null,empty String,array or Collection. func(args) A function call.
  • 6. Accessing Scoped Variable • ${varName} - Means to search the PageContext, the HttpServletRequest, the HttpSession, and the ServletContext, in that order, and output the object with that attribute name. - PageContext does not apply with MVC. • Equivalent forms - ${name} - <%= pageContext.findAttribute("name") %> - <jsp:useBean id="name” type="somePackage.SomeClass” scope="...“> <%= name %>
  • 7. Accessing Bean properties • ${varName.propertyName} - Means to find scoped variable of given name and output the specified bean property • Equivalent forms - ${customer.firstName} <%@ page import=“model.NameBean" %> <% NameBean person = (NameBean)pageContext.findAttribute("customer"); %> <%= person.getFirstName() %>
  • 8. Accessing Bean properties • Equivalent forms - ${customer.firstName} - <jsp:useBean id="customer” type="coreservlets.NameBean” scope="request, session, or application" /> <jsp:getProperty name="customer” property="firstName" /> • This is better than script on previous slide. - But, requires you to know the scope - And fails for subproperties. • No non-Java equivalent to ${customer.address.zipCode}
  • 9. Accessing persisted value • Scope Examples • Accessing a page-scoped attribute named as firstName: ${pageScope.firstName} • Accessing a request-scoped attribute named as firstName: ${requestScope.firstName} • Accessing a session-scoped attribute named as 'lastName' (null if not found): ${sessionScope.lastName} • Page Context Examples • ${pageContext.request.protocol} $ • {pageContext.response.locale} • ${pageContext.session.id} ${pageContext.servletContext} Above we are accessing request, response, session, and application properties, using the pageContext implicit object.
  • 10. Dot and array Notations Equivalent forms – ${name.property} – ${name["property"]} • Reasons for using array notation – To access arrays, lists, and other collections • See upcoming slides – To calculate the property name at request time. • {name1[name2]} (no quotes around name2) – To use names that are illegal as Java variable names • {foo["bar-baz"]} • {foo["bar.baz"]}
  • 11. Accessing Collections • ${attributeName[entryName]} Works for - Array. Equivalent to theArray[index] - List. Equivalent to theList.get(index) - Map. Equivalent to theMap.get(keyName) • Equivalent forms (for HashMap) - ${stateCapitals["maryland"]} - ${stateCapitals.maryland} • But the following is illegal since 2 is not a legal var name - ${listVar.2}
  • 12. Reading Cookie using EL • Cookie Example • addCookies.java Cookie c=new Cookie("name","test"); • res.addCookie(c); • Test.jsp • Name : ${cookie["name"]} • Value : ${cookie["name"].value} • Here in addCookies.java we are creating a new Cookie,These values can be retrieved in jsp by using ${cookie.xxxx}.
  • 13. Using EL in custom tags • EL expressions can be used: - In static text - In any standard or custom tag attribute that can accept an expression • The value of an expression in static text is computed and inserted into the current output. If the static text appears in a tag body, note that an expression will not be evaluated if the body is declared to be tagdependent
  • 14. Using EL in custom tags • There are three ways to set a tag attribute value: - With a single expression construct: - <some:tag value="${expr}"/> - The expression is evaluated and the result is coerced to the attribute's expected type. • With one or more expressions separated or surrounded by text: - <some:tag value="some${expr}${expr}text${expr}"/> - The expressions are evaluated from left to right. Each expression is coerced to a String and then concatenated with any intervening text. The resulting String is then coerced to the attribute's expected type. • With text only: - <some:tag value="sometext"/> - In this case, the attribute's String value is coerced to the attribute's expected type.
  • 15. Advantages of Expression language • Concise access to stored objects. - To output a “scoped variable” (object stored with setAttribute in the PageContext, HttpServletRequest, HttpSession, or ServletContext) named saleItem, you use ${saleItem}. • Shorthand notation for bean properties. - To output the companyName property (i.e., result of the getCompanyName method) of a scoped variable named company, you use ${company.companyName}. To access the firstName property of the president property of a scoped variable named company, you use ${company.president.firstName}. • Simple access to collection elements. - To access an element of an array, List, or Map, you use ${variable[indexOrKey]}. Provided that the index or key is in a form that is legal for Java variable names, the dot notation for beans s interchangeable with the bracket notation for collections.
  • 16. Advantages of Expression language • Succinct access to request parameters, cookies, and other request data. - To access the standard types of request data, you can use one ofseveral predefined implicit objects. • A small but useful set of simple operators. - To manipulate objects within EL expressions, you can use any of several arithmetic, relational, logical, or empty-testing operators. • Conditional output. - To choose among output options, you do not have to resort to Java scripting elements. Instead, you can use ${test ? option1 : option2} • Automatic type conversion. - The expression language removes the need for most typecasts and for much of the code that parses strings as numbers. • Empty values instead of error messages. - In most cases, missing values or NullPointerExceptions result in empty strings, not thrown exceptions.
  • 17. Summary • The JSP 2.0 EL provides concise, easy to read access to - Bean properties - Collection elements - Standard HTTP elements such as request parameters,request headers, and cookies • The JSP 2.0 EL works best with MVC - Use only to output values created by separate Java code • Resist use of EL for business logic