| Author |
use c:forEach tag inside another c:forEach tag
|
Geraldine, Wang
Greenhorn
Joined: Jul 26, 2005
Posts: 2
|
|
Hi, I've got en error when I tried to use <c:forEach> inside another <c:forEach> to display a vector of String arrays. The error message is: javax.servlet.ServletException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer. The concerned section of the javabean mybean.java is: //connect to database to get the resultset ... ResultSet rs = cst.getResultSet(); if (rs != null) { myVector = new Vector(); while (rs.next()) { String myArray[] = new String[10]; myArray[0]=rs.getString(1); myArray[1]=rs.getString(2); ... myArray[9]=rs.getString(10); myVector.addElement(myArray); } rs.close() } ... The concerned jsp calling the bean is: <jsp:useBean id="theBean" scope="session" class="mybean" /> <jsp:setProperty name="theBean" property="..." /> <% ... Vector myVector=theBean.getResultFromDatabaseIntomyVector(); pageContext.setAttribute("myVector",myVector); %> <table> <c:forEach var = 'vectorItem' items='${myVector}'> <tr> <c:forEach var = 'arrayItem' items='${vectorItem.value}'> <td><c ut value='${arrayItem}'/></td> </c:forEach> </tr> </table> Can anyone show me what's the right jsp for displaying a vector of String arrays? Thanks in advance. Geraldine
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56179
|
|
"Geraldine Geraldine", There aren't may rules that have been put into place here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it. In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Thanks! bear Forum Bartender
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Geraldine, Wang
Greenhorn
Joined: Jul 26, 2005
Posts: 2
|
|
Hi all, I've got the answer to this problem already. The correct jsp bit should be: <table> <c:forEach var = 'vectorItem' items='${myVector}'> <tr> <c:forEach var = 'arrayItem' items='${vectorItem}'> <td><c out value='${arrayItem}'/></td> </c:forEach> </tr> </c:forEach> </table>
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: use c:forEach tag inside another c:forEach tag
|
|
|