Expression Language Elements

JSP Expression Language (EL) makes it possible to easily access application data stored in JavaBeans components and other objects like request, session, application etc. JSP EL allows us to create expressions both (a) arithmetic and (b) logical. It is the newly added feature in JSP technology version 2.0.
Syntax of Expression Lanaguage

${expr}

There are two ways to use EL in JSP page
  • As an attribute value in standard and custion actions. For example :
    <jsp:include page="${location}">
  • Within template text, such as HTML. For example
    <h1> Welcome ${user} </h1>
EL Implicit Object
Implicit Objects Description
pageScope it maps containing paget-scoped attributes and their value.
requestScope it maps containing request-scoped attributes and their value.
sessionScope it maps containing session-scoped attributes and their value.
applicationScope it maps containing application-scoped attributes and their value.
param it maps containing request parameter and single string value.
paramValues it maps containing request parameter to an array of values.
header it maps containing header name to the single string value.
headerValues it maps containing header name to an string array of values.
cookie it maps containing given cookie name and their values.
initParam it maps the context-initialization parameters.
pageContext it provides access JSP PageContext object for the current page.
Basic Operators in EL:
Arithmetic Operators in EL:
Arithmetic Operators Operator
Addition +
Subtraction -
Multiplication *
Division / and div
Remainder % and mod
Comparision Operators in EL:
Comparision Operators Operator
Equals == and eq
Not equals != and ne
Less than < and lt
Greater than > and gt
Less than or equal <= and le
Greater than or equal >= and ge
Logical Operators in EL:
Logical Operators Operator
and && and and
or || and or
not ! and not
EL example using param implicit object
The param and paramValues objects is used to access the parameter values normally available through the request.getParameter and request.getParameterValues methods.
index.html
<html> <head> <title>welcome example </title> </head> <body> <form action="display.jsp" method="post"> User Name <input type="text" name="user"> &nbsp; <input type="submit" value="Submit"> <br> </form> </body> </html>
display.jsp
<%@ page language="java" %> <html> <head> <title>display page</title> </head> <body> ${param.user} <h3> Another way to display parameter value :</h3> ${param["user"]} </body> </html>
Output
Expression language
Expression language
Download this example
 



 

Latest Tutorial


Most Visited Tutorial