Skip to content

4 JSP EL

plor10 edited this page Nov 15, 2018 · 1 revision

WEEK 5: JSP

EXPRESSION LANGUAGE (EL) Matt Green MS.Ed , Instructor at WCTC 152

197 DISTRIBUTED JAVA E L Overview 2 What is EL? § We use Scriptlets and JSP expressions to retrieve attributes and parameters in JSP with java code for the View. § For web designers, java code is hard to understand and that’s why JSP Specs 2.0 introduced Expression Language (EL) through which we can get attributes and parameters easily using HTML like tags . § Expression language syntax is ${name } and we will see how we can use them in JSP code. 3 JSP EL Implicit Objects IMPLICIT OBJECTS DESCRIPTION pageScope A map that contains the attributes set with page scope. requestScope Used to get the attribute value with request scope. sessionScope Used to get the attribute value with session scope. applicationScope Used to get the attributes value from application scope. param Used to get the request parameter value, returns a single value paramValues Used to get the request param values in an array, useful when request parameter contain multiple values. header Used to get request header information. headerValues Used to get header values in an array. cookie Used to get the cookie value in the JSP initParam Used to get the context init params, we can’t use it for servlet init params pageContext Same as JSP implicit pageContext object, used to get the request, session references etc. example usage is getting request HTTP Method name. 4 JSP EL Operators 1. EL Property Access Operator or Dot (.) Operator JSP EL Dot operator is used to get the attribute values . ${ firstObj.secondObj } In above expression, firstObj can be EL implicit object or an attribute in page, request, session or application scope. For example, ${ requestScope.employee.address } Note that except the last part of the EL, all the objects should be either Map or Java Bean, so in above example requestScope is a Map and employee should be a Java Bean or Map. If scope is not provided, the JSP EL looks into page, request, session and application scope to find the named attribute. 5

Clone this wiki locally