A simple program using EL in JSP

By: Daniel Malcolm 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

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.

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

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.

web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= ➥
"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
</web-app>

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.


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

Comments(0)


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 )
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
NetworkClient
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