An enumeration allows you to run through a collection of objects.  Once
you've reached the end, it does not go back to the top.  If it did, you
wouldn't know when you reached the end and you'd have yourself an endless
loop.  You can however reuse the same enumeration variable like this:

String name;
String value;
Enumeration enum = request.getParameterNames();
Hashtable hash = new Hashtable();

<snip>

while(enum.hasMoreElements()) {
       name = (String)enum.nextElement();
       value = request.getParameter(name);
       hash.put(name, value);
       System.out.println(hash.get(name));
}
enum = request.getParameterNames();
while(enum.hasMoreElements()) {
     name = (String)enum.nextElement();
     value = (String)hash.get(name);
     System.out.println(value);
     msg.println(name + ": " + value);
}

    (*Chris*)

----- Original Message -----
From: Message UK <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 21, 1999 5:34 AM
Subject: Enumeration for http parameters


> Hello all. I have an email servlet which processes a form. I use an
> Enumeration to get the parameter names, the values of which I then put
into
> a hashtable (don't ask). When I get the values out again to output, I find
I
> have to use a second Enumeration to get the parameter names. If I don't,
> nothing is retrieved from my hastable. Does the Enumeration object "empty"
> as the elements in it are retrieved? Thanks so much.
>
> Enumeration enum = request.getParameterNames();
> Enumeration enum2 = request.getParameterNames();
>
>
> file://we'll store the submitted parameters here
> Hashtable hash = new Hashtable();
>
> <snip>
>
> while(enum.hasMoreElements())
> {
>
>         String name = (String)enum.nextElement();
>         String value = request.getParameter(name);
>
>         hash.put(name, value);
>
>         System.out.println(hash.get(name));
>
> }
>
>
> <snip>
>
> while (enum2.hasMoreElements())
> {
> String name = (String)enum2.nextElement();
> System.out.println((String)hash.get(name));
>
> msg.println(name + ": " + (String)hash.get(name));
> }
>
>
>
> D Lampon
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to