• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:forEach doubt

 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Can anyone post code on how to print values from 1 to 10 (for eg)
using the c:forEach construct in jstl

Thanks
Shiva
 
PNS Subramanian
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this


Env: Tomcat 5.0/JSTL 1.1
Using web.xml corresponding to

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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4"


Any change in any of these(Env details) seems to be altering the behaviour - or being a starter, i seem to experience a different behaviour.
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Subramaniam

In the code sent by you

<c:forEach var="counter" begin="1" end="${10}">

is the $ symbol required for 10
How come it is required for end but not for begin

Thanks
Shiva
 
PNS Subramanian
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isnt required - it was just to show that code would work with a ${} at either begin or end. All the forms shown below would work okay

<c:forEach var="counter" begin="${1}" end="10">
<c:forEach var="counter" begin="${1}" end="${10}">
<c:forEach var="counter" begin="1" end="10">
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic