A simple program using EL in JSP

By: Daniel Malcolm Emailed: 1673 times Printed: 2153 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

Now you’ll learn how you can use the EL within the body of a JSP page so that you can produce dynamic content. Listing below shows an example of a JSP page with some dynamic content generated by the EL. This page displays the value of a parameter (passed to the page) called name. The user is then given a text field in which to enter a new name, and a button to submit the name back to the page for another greeting.

<title>EL and Template Text</title>
body, td {font-family:verdana;font-size:10pt;}
<h2>EL and Template Text</h2>
<table border="1">
<td colspan="2">Hello ${param['name']}</td>
<form action="templateText.jsp" method="post">
<td><input type="text" name="name"></td>
<td><input type="submit"></td>

To run this example, you need to deploy it into a JSP 2.0– or JSP 2.1–compliant web container. As with all examples in this book, we will be using Tomcat 5.5, so you’ll need to create the deployment descriptor shown below.

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation= ➥

Here is the complete list of steps needed to create, deploy, and run this example:

  1. Create the directory %TOMCAT_HOME%\webapps\expressionLanguage\WEB-INF.
  2. Create the web.xml file shown in Listing 3-2. Save it to the webapps\expressionLanguage\
    WEB-INF folder.
  3. Create the JSP page in Listing 3-1 and save it to the webapps\expressionLanguage folder.
  4. Start Tomcat, if needed, open your web browser, and go to

Figure shows the page that should appear in the web browser.

The templateText.jsp displays the value submitted by the user. As you can see, this page is a very simple, personalized greeting. When the page first loads, there will be no request parameter, so the greeting will be only the word “Hello.” When the Submit Query button is clicked, the request is submitted with the parameter name. The JSP page accesses this parameter and uses an EL statement to print the greeting. You’ll look at how the request variable is accessed later, in the "Expression-Language Implicit Objects" section. For now, try entering different values within the text box and clicking Submit Query.

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 Daniel Malcolm
javac options in Java
Operator Precedence in Java
Calling Multiple Listeners in JSF
Using free() Function in C
ForwardAction in Struts
Listing Files and Directories sample program in C
Binary Tree - (Self-referential Structures) example program in C
A simple program using EL in JSP
Command-line Arguments in C
Example Calculator program in C - describing use of External Variables in C
Assignment Operators and Expressions in C
The for statement in C
JSF Basics
assert() Versus Exceptions in C++
RMS Basics in J2ME

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: 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 )
Automatically Refreshing a JSP
JSP CheckBox Example
JSP Alert Example
JSP Program for display Date
Uploading a file to a server using JSP
The BodyTag Interface in JSP
JSP Example to connect to MS SQL database and retrieve records
Retrieving a Portion of a String
Comparison operators in JSP
JSP Example to connect to MS SQL database using Tomcat Connection Pool
Sending Email using JSP
What are the different scopes in JSP?
Embedding java codes in jsp sciptlets
A Simple Servlet Generating Plain Text
The Advantages of JSP
Most Emailed Articles (in JSP)
Click to Activate and Use this control
The Servlet Life Cycle
Textarea Object
The JSP Program running first Time.
Embedding java codes in jsp sciptlets
Debugging Servlets
A JSP page that gets properties from a bean
What is JSP?
A Servlet That Generates HTML
The Advantages of JSP
Document Object
Password Object
Retrieving a Portion of a String
Working with Status Bar Messages
NotifyUtil::java.net.ConnectException: Connection refused: connect