Expression Language - EL

Introduction to Expression Language

The Expression Language (EL) simplifies the data accessibility from various type of application objects like Java Beans, request, session and application etc. There are many implicit objects, operators and reserve words in EL. It is the newly added feature in JSP technology version 2.0.

Syntax

${expression}
${EL.Statement}
${attrName}
${attrName[index]}
${OneObject.MemeberObject.PropertyNameOfMemberObject}

EL implicit object

  • param
  • paramValues
  • header
  • headerValues
  • cookie
  • pageScope
  • requestScope
  • session’scope
  • applicationScope
  • initParam
  • pageContext(*)

param and paramValues

  • These two EL implicit objects are used to collect the request parameters and its values
  • When param is used then internally request.getParameter() method will be called
  • When paramValues is user then internally request.getParameterValues() will be called

Usage:

  • ${param.name}
  • ${param.course}
  • ${paramValues.course[0]}
  • ${ paramValues.course[1]}

header and header values

  • These two EL implicit objects are used to collect the request headers
  • When header is used then internally request.getHeader() method will be called
  • When headerValues is used then internally request.getHeaderValues() will be called

Usage:

  • ${header.host}
  • ${header.referer}
  • ${headrValues.accept-language[0]}
  • ${headrValues.accept-language[1]}

cookie

  • This EL implicit object is used to collect the request cookies

Usage:

  • ${cookies.<cookieName>.value}
  • ${cookie.email.value}

initParam

  • This EL implicit object is used to collect the context parameters from ServletContext obj

Usage:

  • ${initParam.institute}
  • ${initParam.website}

pageContext

  • This EL implicit object allows to access all other JSP implicit objects and their properties

Usage:

  • ${pageContext.session.id}
  • ${pageContext.session.length}
  • ${pageContext.request.removeAddr}
  • ${pageContext.request.method}
  • ${pageContext.request.requestURL}
  • ${pageContext.request.contentType}

pageScope, requestScope, sessionScope, applicationScope

  • In servlet class, you can store the data as attribute
  • In JSP, you can collect the attribute data and display that data
  • You can store the following type of data as attribute in the required scope
  1. String, Wrappers and Date
  2. Collection of String, Wrappers and Date(****JSTL)
  3. Collection of Collections(****JSTL)
  4. User defined objects eg: Student, User, Book
  5. Collection of user defined object
  6. Map object
  7. Collection of Map objects(****JSTL)

EL - String, Wrappers and Date

EL - Collection of String, Wrappers and Date

User defined objects

Collection of user defined objects

Map objects

Collection of maps