File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getParameters order

 
Erik Pragt
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Erik Pragt
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Patrick Metz
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic