• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JSP Expression Language (EL)

January 24, 2014 //  by Krishna Srinivasan//  Leave a Comment

  • Java EE Tutorials
  • JSP Tutorials
  • Recommended Books for Java Server Pages (JSP)

Expression Language(EL) is to access application data stored in JavaBeans components.

The Syntax of EL in a Jsp is:

${expression}

General Example for EL

Let us create two files namely as expr.jsp and expprocess.jsp.

Listing 1:expr.jsp

<html>
<head>

<title>Expression Example</title>
</head>
<body><h3>welcome to javabeats</h3>

<%
session.setAttribute("abc","javabeats");
%>

<a href="expprocess.jsp">visit</a>

</body>
</html>

This file is used to get input from user. We have used sessionscope object for printing the data that is saved in session scope using EL. The sessionScope object will been explained in next sections.

Listing 2:expprocess.jsp

<html>
<head>

<title>Insert title here</title>
</head>
<body>
Value is ${sessionScope.abc }

</body>
</html>

This file is a process file where in user sends request , which in turn prints the name of the user using EL. Here ${sessionScope.adc} is a expression Language(EL)tag.

Execute the jsp file expr.jsp in Eclipse by selecting Run As > Run On Server an output as below would be seen:
jsp_el1_demo

Now click on the link and the you would be take to the screen:

jsp_el2_demo

Basic Operator of EL

Expression language in JSP supports most of operators supported by Java.

Types of Operator:

  • Arithmetic operators
  • Relational Operators
  • Logical Operators
  • Empty Operators

Arithmetic operators

This table lists all the arithmetic operators supported by JSP EL.

Operator Symbol Description
+ Addition
– Unary operator or minus
/ and div Division
* Multiplication
% and mod Remainder

Relational Operator

This table lists all the relarional operators supported by JSP EL.

Operator Symbol Description
= = and eq Equals
!= and ne Not equals
< and lt Less than
> and gt Greater than
<= and le Less than or equal
>= and ge Greater than or equal

Logical Operator

This table lists all the logical operators supported by JSP EL.

Operator Symbol Description
&& and AND and
|| and or Or
! and not not

Implicit Object in JSP EL

JSP developers can directly use implicit objects in an EL Expression.

Implicit Object Description
pageContext It is used to manipulate page attributes and access object request, session etc
param Request parameter to a single string parameter value.
paramValues Request parameter to an array of values
Header Request Header names to a single string header value
headerValues Request Header names to an array of values
pageScope Request page-scoped attribute names to the to their values
requestScope Request request-scoped attribute names to the to their values
sessionScope Request session-scoped attribute names to the to their values
applicationScope Request application-scoped attribute names to the to their values
cookie Request cookie names to a single Cookie value
initParam Context initialization parameter names to their string parameter values

Previous Tutorial : Send Mail using JSP || Next Tutorial : Cookie Handling in JSP

Category: Java EETag: JSP Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Upload a File Using JSP
Next Post: Cookies Handling in JSP »

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact