File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL  forEach tag" Watch "JSTL  forEach tag" New topic
Author

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" %>
<html>
<head>
<title>Count to 10 Example(using JSTL)</title>
</head>
<body>
<c:forEach var="i" begin="1" end="10" step="1">
<c ut value="${i.value}" />
</br>
</c:forEach>
</body>
</html>
Now instead of priting values from 1 to 10 it prints {i.value} string !!!
why it is not priting numbers ???
Can anybody help
thanks
-Anand
ChandraMouli Vidiyala
Greenhorn

Joined: Dec 19, 2002
Posts: 12
Anand,
you have to use <c ut value="${i}" />
not <c ut value="${i.value}" />
-Mouli.
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 !
thanks
-Anand
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).


42
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hi Jeroen,
thanks.
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
-Anand
Eric Suen
Greenhorn

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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
</web-app>
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..
-Anand.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL forEach tag