Two Laptop Bag*
The moose likes JSP and the fly likes Getting back param values in the correct order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting back param values in the correct order" Watch "Getting back param values in the correct order" New topic
Author

Getting back param values in the correct order

Nicholas Giaimo
Greenhorn

Joined: Oct 18, 2012
Posts: 2
Hello everyone,

After doing some searching on here and on Google I have not been able to find a definitive answer the the following question.

I am currently trying to get a list of all the values from this small form



via the following code in results.jsp



Now, this works, but the issue is that they are not in the same order as they were in the form. I would normally just call ${param.(nameofparameter)} but I will not know which form is being sent to results.jsp.

Basically, I need to get all of the param values from any possible form without knowing the name of the parameters, IN ORDER. Is that possible?

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18155
    
    8

Hi Nicholas, welcome to the Ranch!

Short answer: No, that isn't possible.

Longer answer: I've never heard of anybody requiring an order for the parameters. Why do you need one? What problem is that solving? (There might be a way of putting the parameters in order, but it would be up to you to implement that.)
Nicholas Giaimo
Greenhorn

Joined: Oct 18, 2012
Posts: 2
Thank you for the welcome!

What I was planning on doing was to was have them added to a List of Strings and then sent as a parameter in a method to generate an output. The method would know for each form which parameter would be where in the List.

Now that I am thinking about it without that plan since it would not work, I could probably just use a Map, correct? I have never used Maps before so I will have to look that up.

Anyway thank you for the answer!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18155
    
    8

Yes, a Map would be ideal because that's in fact how the parameters are stored in the request. And you'll find that HttpServletRequest has a getParameterMap method which gives you that Map. So yes, check out Map. Here's a link to the Java Collections Tutorial which tells you almost everything you would ever want to know about collections -- including maps.

(And after you reach a certain point in that tutorial, you'll see why you aren't getting the parameters in the order they appeared in your form.)
 
Consider Paul's rocket mass heater.
 
subject: Getting back param values in the correct order
 
Similar Threads
Ajax code getting null value
Question on BUTTON name/value pairs sent from JSP
Dropdown list not displaying with textfield in form
Unable to run web application(java) on tomcar server
FileUpload - Request empty with IE8