wood burning stoves 2.0*
The moose likes JSP and the fly likes c:forEach question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "c:forEach question" Watch "c:forEach question" New topic
Author

c:forEach question

Uma Viswanathan
Ranch Hand

Joined: Jun 14, 2001
Posts: 126
I am getting input from the user using html form. When the user clicks submit button, the input is sent to a jsp page.

In the html form, i have a checkbox (the user can select more than one value). I wrote the following code in the jsp page (say the parameter name is color).

<c:if test="${!empty param.color}">
<c:set var="strColor" value="${param.color}"/>
<c:forEach var="strC" items="${strColor}">
<c ut value="${strC}"/>
</c:forEach>
</c:if>

(or)

<c:if test="${!empty param.color}">
<c:forEach var="strC" items="${param.color}">
<c ut value="${strC}"/>
</c:forEach>
</c:if>

Both the codes display only the first value selected in the checkbox.

If i write scriptlet request.getParamaterValues("color"), it works. But i want to write it using JSTL.

Please help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

You seem to understand the difference between request.getParameter() and request.getParameterValues().

The same applies to the JSTL implicit objects param and paramValues.
[ August 04, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

P.S. Clicking the 'Disable smilies in this post' checkbox when you submit code samples will cause your <cut> tags to look less surprised.
Uma Viswanathan
Ranch Hand

Joined: Jun 14, 2001
Posts: 126
Thank you very much Bear Bibeault. I am new to jsp. So, learning...

I read in the book about param, but did not know about paramValues.

Thank you very much again.
 
Don't get me started about those stupid light bulbs.
 
subject: c:forEach question