Programming Tutorials

A simple program using EL in JSP

By: Daniel Malcolm in JSP Tutorials on 2007-09-23  

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"
<td><input type="text"
<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. We will be using Tomcat 5.5, so you'll need to create the deployment descriptor shown below.


<?xml version="1.0"
<web-app xmlns=""

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 http://localhost:8080/expressionLanguage/templateText.jsp.

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.

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in JSP )

Latest Articles (in JSP)