aspose file tools*
The moose likes Servlets and the fly likes request.getParameters order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getParameters order" Watch "request.getParameters order" New topic
Author

request.getParameters order

Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Hello I have a question:
In which order does a request.getParameters come?
To illustrate my question, a small piece of code:

Now, when I change the name of the Fields, the order in which they are printed also change...this is ofcourse something I don't want, cause I want to insert the data in a Database and for the, the order in which they are inserted is very important...
(In short, my actual problem is to read a page dynamically, and put the values in an Insert Statement...so if I'm doing something wrong, can someone please tell me??)
Thanks in Advance,
Erik Pragt
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
I don't know much about DB (my weakest point) but if you have to depend on the order of parameters being fixed, I'd say re-think your approach.
I recommend you associate a param name with a value, independently of what order it "came in"


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Can you give an example of that?
PS, this has nothing to do with DB's, it's just a mere example of using it in combination with DB's. It could e.g. also be used for saving it to a file, creating an array with these values, whatever, as long as the order in which the value came in stays the same, or that I have some control about it.
[This message has been edited by Erik Pragt (edited October 08, 2001).]
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Then how about knowing the NAMES of the parameters beforehand (properties file?) and then reading them by name in the order that you want?
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
That's also not possible, cause that would screw up the idea of having the page post data dynamically...changing a properties file is taking (almost) the same effort as changing my jsp code.
The idea was that I could dynamically load a form, and without knowing the correct number of parameters, still display them in a certain order. But somehow, the order keeps shifting when I change the names of the input field.
Now my question is: in which order do they shift, and why??
Erik
Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200
Hi,
Even i faced a similar problem when i wrote my servlets. What i feel is that u don't have to spend ur time finding the order in which the parametrs are sent, coz that won't get u any where.
What i have done to overcome this problem is, i wrote a javascript that gets all the field names in the form and puts them in a hidden field(separated by a delimiter). Now using javascript u can order the fields in the order they appear in the form. Now since the name of the hidden field is a constant, all i need is to read the hidden field value, tokenize it with my delimiter. Here each token will be the field name. now read them as parameters.
hope u got it
..saj
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
Just thought I'd add this little bit. page 67 of Marty Hall's Core Servlets & JSP has a core warning that reads..
"Don't count on getParameterNames returning the names in any particular order"

I have run the same servlet with getParameterNames() several times, almost every time, the parameters are returned in a different order.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Patrick Metz
Greenhorn

Joined: Sep 28, 2001
Posts: 3
How about creating a Java-Bean that receives the parameters?
You could automatically let the bean be filled with your values

and get the parameters later in the order you want!

greetz
frag
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: request.getParameters order
 
Similar Threads
java.util.Enumeration
Sequence of Parameters
Enumeration
Getting null while trying to get value of Multiple list
jsp:setProperty/Bean equivalent for request.getParameterValues