- 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:
Now click on the link and the you would be take to the screen:
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