BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

JSP Expression Language (EL) – JSP Tutorial

Last Updated: September 10, 2022 by Chaitanya Singh | Filed Under: JSP tutorial

Expression language (EL) has been introduced in JSP 2.0. The main purpose of it to simplify the process of accessing data from bean properties and from implicit objects. EL includes arithmetic, relational and logical operators too.

Synatx of EL:

${expression}

whatever present inside braces gets evaluated at runtime and being sent to the output stream.

Example 1: Expression language evaluates the expressions

In this example we are evaluating the expressions with the help of EL.

<html> 
<head>
 <title>Expression language example1</title>
</head>
<body> 
${1<2}
${1+2+3}
</body> 
</html>

Output:

EL-example1

Example 2: Value fetch using param variable of expression language

In this example we are prompting user to enter name and roll number. On the other JSP page we are fetching the entered details using param variable of EL.

index.jsp

<html> 
<head>
 <title>Expression language example2</title>
</head>
<body> 
<form action="display.jsp"> 
Student Name: <input type="text" name="stuname" /><br>
Student RollNum:<input type="text" name="rollno" /><br>
<input type="submit" value="Submit Details!!"/> 
</form> 
</body> 
</html>

display.jsp

<html>
<head>
<title>Display Page</title>
</head>
<body>
 Student name is ${ param.stuname } <br>
 Student Roll No is ${ param.rollno }
</body>
</html>

Output:

EL-example2

Expression-lang-example2

Example 3: Getting values from application object.

In this example we have set the attributes using application implicit object and on the display page we have got those attributes using applicationScope of Expression language.

index.jsp

<html>
 <head>
 <title>EL example3</title>
 </head>
 <body>
 <%
 application.setAttribute("author", "Chaitanya");
 application.setAttribute("Site", "BeginnesBook.com");
 %>
 <a href="display.jsp">Click</a>
 </body>
 </html>

display.jsp

<html>
 <head>
 <title>Display Page</title>
 </head>
 <body>
 ${applicationScope.author}<br>
 ${applicationScope.Site}
 </body>
 </html>

Output:

Expression-lang-example3

EL-example3

EL predefined variables:

Similar to implicit objects in JSP we have predefined variables in EL. In the above examples we have used param and applicationScope, they are also the part of these variables.

pageScope: It helps in getting the attribute stored in Page scope.
pageContext: Same as JSP PageContext object.
sessionScope: Fetches attributes from session scope, set by session object.
requestScope: It used for getting the attributes from request scope. The attribute which are set by request implicit object.
param: Similar to ServletRequest.getParameter. Refer Example 2.
applicationScope: Used for getting Applicaton level attributes. Same what we see in Example 3.
header: It helps in getting HTTP request headers as Strings.
headerValues: Used for fetching all the HTTP request headers.
initParam: It links to context initialization parameters.
paramValues: Same as ServletRequest.getParmeterValues.
cookie: It maps to Cookie object.

Top Related Articles:

  1. JSP Scriptlet Tag (Scripting elements)
  2. Java Server Pages (JSP) Life Cycle
  3. Include Directive in JSP
  4. Config Implicit Object in JSP with examples
  5. JSP forward action tag

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. Ashish Kumar Rao says

    August 31, 2014 at 5:02 PM

    best for learner ,impressive learning tutorial for freshers…!

    that’s great help for me——Ψ

    thanks a lot Sir.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE

Scripting Elements

  • Scriptlet Tag
  • Expression tag
  • Declaration tag

Implicit Objects

  • Implicit Objects
  • JSP Request
  • JSP Response
  • JSP Config
  • JSP Application
  • JSP Session
  • JSP Out
  • JSP pageContext
  • JSP Exception
  • Validate session

JSP directives

  • JSP Directives
  • Include Directive

JSP Exception

  • Exception handling

JSP Action

  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty

Expression language

  • Expression language

JSP Custom Tags

  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap