wood burning stoves 2.0*
The moose likes JSP and the fly likes JSTL  forEach tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL  forEach tag" Watch "JSTL  forEach tag" New topic

JSTL forEach tag

Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hi All,
I am using Tomcat 5.0.18 , WinXP and J2sdk1.4.2_03
I installed standard tag libray from jakarata.apache.org. following code snippet shows the use of forEach tag.
<%@ taglib uri="http://jakarta.apache.org/taglibs/core" prefix="c" %>
<title>Count to 10 Example(using JSTL)</title>
<c:forEach var="i" begin="1" end="10" step="1">
<c ut value="${i.value}" />
Now instead of priting values from 1 to 10 it prints {i.value} string !!!
why it is not priting numbers ???
Can anybody help
ChandraMouli Vidiyala

Joined: Dec 19, 2002
Posts: 12
you have to use <c ut value="${i}" />
not <c ut value="${i.value}" />
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hi Mouli,
I tried <c ut value="${i}" /> but same problem !
It gives {i} in output and not the values of i !
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093

try this instead.
It might still not work as c:forEach iterates over a List and you supply a List (but this might be a form I haven't seen before).

Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hi Jeroen,
I tried the piece of code you supplied. Same problem persists !
now it prints ${v.count} on the output !
any clues ? Thanks for your help
Eric Suen

Joined: Mar 17, 2004
Posts: 3
By default, the EL evaluation is enabled for Web Applications using
a Servlet 2.4 or greater web.xml, and disabled otherwise.
you can make your web.xml like this to enable EL:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
and BTW: you can just use ${i} instead of <c: out value="${i}" />.
[ March 20, 2004: Message edited by: Eric Suen ]

<a href="http://www.spket.com" target="_blank" rel="nofollow">Spket IDE</a> - Development Tool for RIA.
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hey Eric,
Thanks a bunch ,it works now !!
I digged everywhere but couldn't find the solution.
thanks again..
I agree. Here's the link: http://aspose.com/file-tools
subject: JSTL forEach tag
Similar Threads
error in JSTL
EL does not work
Doubt in JSTL
According to TLD or attribute directive in tag file, attribute value does not accept any expressions
jstl tlds entry in web.xml