Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:forEach question

 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic