| Author |
Looping thrugh an Enumeration Object
|
Kassi Hill
Greenhorn
Joined: Sep 29, 2003
Posts: 24
|
|
Hi All. I am new to JSP. I am writing a very simple JSP that prints out all of the names of the parameters and values in a table. I have posted my code blow, which does work, except that it prints each Heading and data cell in a seperate table. It does not print out all information in the same table. I know I am not looping through the parameterNames right but I just cannot figure out what I need to change. Any help would be appreciated. <% Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); String parameterValue = request.getParameter(parameterName); %> <table border = 1> <tr> <td><%= parameterName %></td></tr> <tr> <td><%= parameterValue %></td></tr> <%}%> </table>
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56153
|
|
Did you look at the HTML that was generated? Since you have the table declaration inside the loop, it gets emitted each time. I'd also highly recommend ditching the Java in the page in favor of the <c:forEach> tag of the JSTL. It'll make the notation much easier to visualize.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Anselm Paulinus
Ranch Hand
Joined: Sep 05, 2003
Posts: 389
|
|
Kassi Hill: Copy this and paste on your code, it should work <table border = 1> <% Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); String parameterValue = request.getParameter(parameterName); %> <tr> <td><%= parameterName %></td> <td><%= parameterValue %></td></tr> <%}%> </table> [ April 09, 2004: Message edited by: Anselm Paulinus ]
|
 |
Kassi Hill
Greenhorn
Joined: Sep 29, 2003
Posts: 24
|
|
Anselm Paulinus, Thank you very much. It worked.
|
 |
 |
|
|
subject: Looping thrugh an Enumeration Object
|
|
|