wood burning stoves*
The moose likes JSP and the fly likes Looping thrugh an Enumeration Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Looping thrugh an Enumeration Object" Watch "Looping thrugh an Enumeration Object" New topic
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: 60752
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
 
Similar Threads
JSP Should recognise fundamental class Enumeration?
Getting null while trying to get value of Multiple list
request.getParameters order
Basic scriptlet / JSP help needed.
Sequence of Parameters