Home Jsp Simple-jsp-example JSTL: String Collection
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

JSTL: String Collection

Advertisement
In this example we are going to set some movies in the attribute var. The var attribute in is used for setting attributes variables. It works like tag but by using we can only set the property of a bean. But if

JSTL: String Collection

        

In this example we are going to set some movies in the attribute var. The var attribute in <c:set> is used for setting attributes variables. It works like <jsp:setProperty> tag but by using <jsp:setProperty> we can only set the property of a bean. But if we want to set the value of a Map, then there we should use <c:set> tag. 

In this example the value which we have set in the var attribute of the <c:set> core action tag will be retrieved by using the <cout> tag which is used to display the information on the browser. It is same as declaration directive <%=------%> in jsp.  We can also show the output in other way also.   For this we are using the core action tag <c: forEach> which we are using for the iteration of the movies. 

The code of the program is given below:

 

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>String Collection Example</title>
</head>

<body>
<strong>Collection Example</strong>

<c:set var="movienames" value="Sholay, Ram Teri Ganga Maili, Awaara, Mughal-e-Azam,
Deewar, Zanjeer, Anand, KKrish" />

<h3>Input Movies:</h3><br><br>

<c:out value="${movienames}" /><br><br>

<h3>Now we are iterating the movies</h3><br><br>

<c:forEach var="movie" items="${movienames}">
<c:out value="${movie}" /><br>
</c:forEach>
</body>
</html>

The output of the program is given below:

Download this example.

        

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 12, 2008

Ask Questions?    Discuss: JSTL: String Collection  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com