File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes passing array parameter in URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "passing array parameter in URL" Watch "passing array parameter in URL" New topic

passing array parameter in URL

Richard Mendoza
Ranch Hand

Joined: Feb 26, 2003
Posts: 48

Is it possible to pass an array object in URL? something like..

var emp = new Array();

emp[0] = "Emp1";
emp[1] = "Emp1";
emp[2] = "Emp1";
emp[3] = "Emp1";

then pass using


then in jsp,


Please advise.
Stefan Evans

Joined: Jul 06, 2005
Posts: 1523
This is more a html/javascript question than JSP.
In order for request.getParameterValues("emp") to work, you have to pass along a url string something like

Notice that the parameter emp appears multiple times, each time with a new value.
You can construct this string yourself in javascript with a simple loop, and navigate to that url.

Alternatively you can use the toString method of an array to turn the values into a comma separated list, and send that as a single parameter.
At the JSP end you would retrieve the parameter, and then use the String.split method to split it on commas, and turn it into a java array.

Whichever approach you use, you should probably use the javascript function window.escape() to escape any characters that might be affected by putting them in a url string.

Good luck,
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63551

If the array is any size at all you will quickly run out of room in the URL, so this is a very poor way to try and pass anything but small amounts of data.

What are you really trying to accomplish?

[Asking smart questions] [About Bear] [Books by Bear]
narayana arya

Joined: Dec 12, 2005
Posts: 12
simply you should retrieve that values by using Enumeration enum1=request.getParameterNames();
if (str.indexOf("emp"))>=0)

by using this u will receive all emp relative parameters and values.
Richard Mendoza
Ranch Hand

Joined: Feb 26, 2003
Posts: 48
Hi Stefan Evans,

That really helps me a lot! Thanks for help!
I agree. Here's the link:
subject: passing array parameter in URL
jQuery in Action, 3rd edition