Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looping thrugh an Enumeration Object

 
Kassi Hill
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anselm Paulinus,
Thank you very much. It worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic