Is this JSTL usage correct?
I want to make a drop down list in HTML. I have coded the following:
<select name="Locations">
<c:forEach var="item" items="${choices}">
option value=<c:out value=${item}/>
</c:forEach>
</select>
If I've understood these tags correctly, choices can be an attribute of the request object and I don't need to precede this with a set statement nor get the attribute in any other way. In choices, I need to supply the full text of the element, e.g.,
"West Campus Building 1">West Campus Building 1
This will allow me then in my servlet to get the locations parameter like usual. Is that correct? I'm doing this because the contents of the list comes from the database and I don't want a database tag in my JSP. That, it seems to me, violates MVC rather badly. THanks.
[1007 byte] By [
klitwaka] at [2007-10-2 12:34:32]

Looks basically ok to me.
You are missing a few quotes and < > symbols.
>If I've understood these tags correctly, choices can be an attribute of
>the request object and I don't need to precede this with a set
>statement nor get the attribute in any other way.
correct.
${choices} evaluates pretty much the same as <%= pageContext.findAttribute("choices") %>
As long as "choices" is an attribute in scope somewhere, it will find it.
>In choices, I need to supply the full text of the element, e.g.,
I don't believe you need to get the full text of the element.
I would prefer to do it like this:
<select name="Locations">
<c:forEach var="item" items="${choices}">
<option value="<c:out value="${item}"/>"><c:out value="${item}"/>
</c:forEach>
</select>
That way your "choices" attribute can be merely a list of the string values to display in the dropdown - which is as it should be.
I am testing JSTL foreach tag. I used the code of the example:
<h3>Iterating over a range</h3>
<c:forEach var="item" begin="1" end="10">
${item}
</c:forEach>
But the follow is showed in the browse:
Iterating over a range
${item} ${item} ${item} ${item} ${item} ${item} ${item} ${item} ${item} ${item}
Iterating over
Is it a problem with libraries? When I run the example over the same Tomcat server, it runs successfully.
Thanks...
Petinati