Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JSTL: another for each and status 
 

In this program we are declaring one array of type String in which we are going to store some movies name in it. This declaration will be done inside the scriptlet directive. Now set the attribute by using the pageContext implicit object.

 

JSTL: another for each and status

                          

In this program we are declaring one array of type String in which we are going to store some movies name in it. This declaration will be done inside the scriptlet directive. Now set the attribute by using the pageContext implicit object. 

To retrieve the values set in the directive we now use <c: forEach> tag which will help us to iterate over the values. In this tag we have used some attributes like var which will help us to iterate the values i.e. movies. The attribute items helps us to get the attribute which we have set in the directive. The varStatus attribute makes a new variable that holds an instance of javax.servlet.jsp.jstl.core.LoopTagStatus.  Use <c:out> to display the result to the browser.

The forEach has one scoped variable called count. The LoopTagStatus class has a count property which gives us the current value of the iteration counter.

The code of the program is given below:

 

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%
String[] movies = {"Sholay", "Maine Pyar kiya", "Jai Santoshi Maa", "Kaho Na Pyaar Hai", "Krish", "Rang De Basanti"};
pageContext.setAttribute("movies", movies, pageContext.PAGE_SCOPE);
%>
<html>
<head>
<title>forEach and status</title>
</head>
<body>
The forEach has one scoped variable called 'count', it tells the 
current position of the element within the collection. <br>
<c:forEach var="movieName" items="${pageScope.movies}" varStatus="status">
Movie Number : <c:out value="${status.count}" /> is
<c:out value="${movieName}" /> <br />
</c:forEach>
</body>
</html>

The output of the program is given below:

Download this example.

 

 

                          

» View all related tutorials
Related Tags: c jsp ide variables script object io methods scope method variable print ip page tag ole instance int ria this

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.