Professional Documents
Culture Documents
Module Objective
At the end of this module, participants will be able to understand:
What EL is How to use Arithmetic operations in EL How to disable/enable evaluation of EL for a JSP How to disable/enable evaluation of all the JSPs in application How to use Comparison operations in EL What are implicit objects in EL and their usage What JSTL is JSTL tags JSTL requirements How to use out tag of core library How to use set and if tags of core library How to use choose, forEach, forTokens, redirect and param tags of core library
2
Introduction to EL
EL stands for Expression Language. EL was introduced in JSTL1.0. Before EL was introduced, scriptlets were used to manipulate the application data. EL makes it possible to access the data stored in Java Bean components. The server side state is integrated with the presentation output using EL. EL expressions can be used in static text. An EL expression is written between the delimiters ${ and } The expression and its delimiters are replaced by the result of expression evaluation.
EL - Arithmetic Operations
Deactivating evaluation of EL
To deactivate evaluation of EL, the isELIgnored attribute of page directive is specified:
The valid values of isELIgnored attribute are true and false. If the value of isELIgnored attribute is true, EL expressions are ignored and they appear in static text. If the value of isELIgnored attribute is false, EL expressions are evaluated by the container. The default value of isELIgnored attribute is false.
EL Comparison Operations
Implicit Objects
Implicit objects defined by JSP Expression Language are:
pageContext = It refers to the context for the JSP page. It contains the reference of the objects like request, response, session and servletContext.
param = Using this, a request parameter name is mapped to a single value. paramValues = Using this, a request parameter name is mapped to an array of values. header = It maps a request header. cookie = It maps a cookie name to a single cookie. initParam = It maps the context initialization parameter name.
paramOutput.jsp
initParamOutput.jsp
cookieOutput.jsp
What is JSTL?
JSTL stands for JSP Standard Tag Libraries. JSTL is a collection of JSP custom tags which have been developed by the Jakarta project. JSTL can help to avoid scripting elements in JSP pages. A JSP page should not have scriptlets containing the Java code. It should be a view page. JSTL offers custom tags through 4 libraries:
core: Provides scripting functions xml: Used for xml processing fmt: Used for internationalization sql: Used for database processing
JSTL tags
Area
Core
Subfunction
Variable support Flow Control URL Management Miscellaneous Core Flow Control Transformation Locale Message Formatting Number and Date formatting SQL Collection length String manipulation
Prefix
c
XML
I18N
fmt
Database Functions
sql fn
JSTL Requirements
The requirements to use JSTL are: Requirement A JSP Server A JSTL implementation Description Apache Tomcat from apache.org Taglib from apache.org jstl.jar and standard.jar
A JSTL document
JSTL pages having JSTL tags
JSTL specification
To be written by you
Run the above jsp page in browser. The following output is displayed:
forTokensExample.jsp
welcome.jsp
The redirect tag is used for forwarding the browser to the specified url. The param tag is used to send some parameter value to the page to which the redirect occurs
Key Points
After completing this course you should be able to:
Tell what EL is Demonstrate how to use arithmetic operations in EL Demonstrate how to enable/disable evaluation of EL Tell what are the various implicit objects in EL Tell what is JSTL and what are various JSTL tags Demonstrate how to use various tags of core library
35