This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Looping thrugh an Enumeration Object  RSS feed

 
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
Posts: 66141
141
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!