Introduction to JSP expression language

By: Abinaya Emailed: 1785 times Printed: 2614 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

One of the features of the JSP specification that you’ll be using most often is the JSP expression language, an intentionally simple language that is, to a large extent, independent from JSP. In previous incarnations of JSP, Java code was embedded into JSP pages in the form of scriptlets, for example:

MyBean bean = new MyBean();
String name = bean.getName();

This scriptlet creates a new instance of a class called MyBean, gets its name property, assigns this to a string variable, and then outputs this string to the page. Now you might be looking at this and thinking, “I can achieve the same thing by using the JSP standard actions (<useBean> and <getProperty>).”

Although this is certainly true, it was previously extremely hard to write a function-rich JSP-based web application without using a number of scriptlets within your pages. In fact, there are many problems associated with using Java code in the form of scriptlets in JSP pages.

The first and most obvious of these is that it’s very common for non-Java programmers to create the user interface for a system. This is because graphic designers are generally better than Java programmers at creating functional user interfaces. The second problem caused by the use of scriptlets is that of maintainability. Embedding large amounts of code into the user interface of a system makes the interface much harder to change and understand.

For all of these reasons, the JSP 2.0 specification introduced an expression language (EL) that can do pretty much everything that scriptlets can do. This language is far simpler to understand than Java and looks very similar to JavaScript. The following are good reasons for this similarity:

• JavaScript is something that most page authors are already familiar with.
• The EL is inspired by ECMAScript, which is the standardized version of JavaScript.

In fact, both ECMAScript and the XPath EL inspired the JSP EL. The EL specification states, “. . . the experts involved were very reluctant to design yet another expression language and tried to use each of these languages, but they fell short in different areas.”

If you’ve been following the progress of JSP, and the JSP Standard Tag Library (JSTL), you’re probably aware that the first expression language was released as part of the JSTL. The EL was then incorporated into the JSP 2.0 specification with JSTL 1.1. At around the same time, the JavaServer Faces (JSF) expert group was developing an expression language for JSF. Because of JSF requirements, the JSF expression language had some differences from the JSP expression language. JSP 2.1 unifies the two versions so that there is a single expression language used for JSP, JSTL, and JSF.

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


1. View Comment

scriptlets when used in a page - helper pattern...i.e. every jsp page has a help java class which incorporates BUTT SIMPLE scriptlets...not the obviously wrong scriptlets from hell always used to justify the explosion of expression languages....used that on several projects and the html folks would just dummy in dynamic stuff...which i would replace with a fall off a log easy to use function call for them....we both did our jobs quickly and efficiently....

now with this CRAP of tags looking like code which then codes java and then codes html and when they are nested becomes unbelievably complex to figure out when and where you can use various tricks...the pages become so complex that not only can web developers not do it....the java developers (with their poor art web designs) are now stuck doing the work because no one else can manage the complexity...

this goes to show what would have happened to java if they had opened it up to soon to the well meaning but complexity driven ghouls of open source

View Tutorial          By: tony at 2009-03-04 17:03:03

Your name (required):

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

Your sites URL (optional):

Your comments:

More Tutorials by Abinaya
How to compile a Java program - javac
The clone() Method in Java
Data Types in Java
JSP Example to connect to MS SQL database and retrieve records
faces-config.xml to DirectTraffic in the JSF Application
Enabling Expression Language Evaluation in JSP
Using malloc() Function in C
ActionErrors and ActionError in Struts
Open, Creat, Close, Unlink system calls sample program in C
Structures and Functions in C
Introduction to JSP expression language
Multi-dimensional Arrays in C (Explained using date conversion program)
A C program similar to grep command in UNIX
Type Conversions in C (String to Integer, isdigit() etc)
Basics of C

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 )
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
JSP CheckBox Example
JSP Alert Example
Comparison operators in JSP
Sending Email using JSP
Uploading an Image to a Database using JSP
Arithmetic Evaluation Using the Expression Language in JSP
The Advantages of JSP
Writing your first JSP page
Uploading a file to a server using JSP
The Request Object in JSP
Disabling Scriptlets in JSP using web.xml
Deploying an Individual JSP on Tomcat
Automatically Refreshing a JSP
Most Emailed Articles (in JSP)
The Tag Life Cycle with Attributes in JSP
Calling JSP from a batch file
JSP Program for display Date
Sessions in JSP
Simple HTML-Building Utilities
Handling Events
Using a DataSource from WebLogic in a JSP
The JSP Program running first Time.
Declaring variable in JSP
The Advantages of JSP
Password Object
Retrieving a Portion of a String
Automatically Including Preludes and Codas in JSP
The Differences Between Simple and Classic Tags in JSP