• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Looping thrugh an Enumeration Object

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anselm Paulinus,
Thank you very much. It worked.
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic