The Basic Syntax Expression Language in JSP

By: Baski Emailed: 1700 times Printed: 2204 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

In this tutorial, you’ll look at the syntax of the EL, see how to use it on a JSP page, and learn the reserved words of the language. After you’ve looked at the basics, you’ll move on to look at how and why you might disable the EL and Java scriptlets within a page or set of pages.

Basic Syntax

No matter where the EL is used, it’s always invoked in a consistent manner, via the construct ${expr} or #{expr}, where expr is the EL expression that you wish to have evaluated. In the EL 2.1 specification, the syntax of ${expr} and #{expr} are equivalent and can be used interchangeably. However, when used with some other Java Platform, Enterprise Edition API, the other API may enforce restrictions on the use of ${expr} and #{expr}. Specifically, when used with JSP pages, the two forms cannot be used interchangeably. Within a JSP page, ${expr} is used for expressions that are evaluated immediately, whereas #{expr} is used for expressions for which evaluation is deferred. Deferred expressions are used with custom actions.

A simple use of the EL is shown here. This piece of code creates a JavaBean and outputs its name property:

<jsp:useBean id="bean" class="MyBean"/>

 This is the recommended way to do this, rather than instantiating the object in a scriptlet.

Just as in any programming language, the EL provides several literals for developers to use. A literal can be of a Boolean, integer, floating point, string, or null type. The following are valid values for each literal type:

  • Boolean: true or false.
  • Integer: This is limited to values defined by the IntegerLiteral regular expression as follows:
    IntegerLiteral ::= ['0'-'9']+

    This regular expression says that an integer is any sequence of digits using the digits from 0 to 9. The specification also allows an integer literal to be preceded by a unary “-” symbol to form negative integer literals. For example, the following are valid integers:

  • Floating point: This is defined by the following FloatingPointLiteral expression:

    FloatingPointLiteral ::= ([''0'-'9'])+ '.' (['0'-'9'])* Exponent?
    | '.' (['0'-'9'])+ Exponent?
    | (['0'-'9'])+ Exponent?
    Exponent ::= ['e','E'] (['+','-'])? (['0'-'9'])+

    This expression is more complex. As with integer literals, a floating-point literal can be preceded by a unary “-” symbol to produce negative floating-point literals. To help you understand this, here are some valid floating-point literals:

  • String: A string is any sequence of characters delimited with either single or double quotes. For example, "a string" and 'a string' are both valid; however, "as' and 'as" are not valid. If you want to represent quotes within a string, then you can use \" for double quotes, or \' for single quotes. Alternately, if the string is delimited by double quotes, you can use single quotes within the string without escaping the single quotes, and vice versa. To represent a \ in a string, you use the escape sequence \\.
  • Null: You can represent null by using the literal null.

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


Be the first one to add a comment

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Baski
Compiling multiple source files and specifying classpath using javac
The equals() Method example in Java
Default Values for Data Types in Java
JSP Example to connect to MS SQL database using Tomcat Connection Pool
<convertNumber> and <convertDateTime> in JSF
Enable/Disable Scripting Elements in JSP
Using calloc() Function in C
lseek() sample program in C
Arrays of Structures example program in C
The Basic Syntax Expression Language in JSP
Initialization of Pointer Arrays in C
Functions returning non-integer values in C
Increment and Decrement Operators in C
Getting Started with C
What is JSF (JavaServer Faces)?

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What is JSP?
An Example Using Servlet Initialization and Page Modification Dates
Select Object
The Basic Syntax Expression Language in JSP
Comparison operators in JSP
The Differences Between Simple and Classic Tags in JSP
Sending Email using JSP
Getting HTTP Request Headers in a JSP
JSP Alert Example
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Server Side Programming
Syntax For JSP Declaratives
Most Emailed Articles (in JSP)
Declaring variable in JSP
What is JSP?
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Server Side Programming
Syntax For JSP Declaratives
Embedding java codes in jsp sciptlets
Tags using in jsp
JSP pages in servlet
Combining Scriptlets with HTML
JSP Directives
Form processing in JSP
JSP Program for display Date