JSTL Example in Eclipse

Introduction :

In this example we will create a dynamic web project.We will create one page where user can enter first name and last name.After submitting the form we will collect the information in another page and display the details of user using JSTL <c:out> tag.


Tools Used

  • JDK 1.6
  • Eclipse Indigo
  • Tomcat 6


JAR files required for this application

  • jstl.jar
  • standard.jar


Introduction :

In this example we will create a dynamic web project.We will create one page where user can enter first name and last name.After submitting the form we will collect the information in another page and display the details of user using JSTL <c:out> tag.


Tools Used

  • JDK 1.6
  • Eclipse Indigo
  • Tomcat 6


JAR files required for this application

  • jstl.jar
  • standard.jar



Directory Structure Of Project

JSTL Example

Follow the steps mentioned below for this example

Step 1: Create Dynamic Web project

Open Eclipse and goto File -> New -> Project and select Dynamic Web Project in the New Project wizard screen.Select Dynamic Web Project and click Next.

JSF Example

Provide the name of the project as JSTLExample. Once this is done, select the target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse environment and click Next -> Next -> Next and Finish.

JSTL Example


Step 2: Add jar files to build path of the project

Copy jstl.jar and standard.jar files to the lib folder of the project directory and add all jar files to the build path of the project.


Step 3: Create JSP files

Create two JSP files: index.jsp and welcome.jsp inside WebContent folder.

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index Page</title>
</head>
<body>
<form action="welcome.jsp" method="post">  
FirstName:<input type="text" name="firstName"/><br/>  
LastName:<input type="text" name="lastName"/><br/>  
<input type="submit" value="Submit"/>  
</form>  
</body>
</html>

welcome.jsp

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Page</title>
</head>
<body>
First Name:<c:out value="${param.firstName}"></c:out><br/>  
Last Name:<c:out value="${param.lastName}"></c:out>  
</body>
</html>

In welcome.jsp file we are using jstl core tag by writing taglib <%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>.Later we are displaying the output by using </c:out>


Output :

JSTL Example

Enter some value and submit we will get welcome page as shown below.

JSTL Example


Download this example(src+lib) developed in eclipse





comments powered by Disqus