File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Passing array from jsp to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing array from jsp to servlet" Watch "Passing array from jsp to servlet" New topic
Author

Passing array from jsp to servlet

Amtul Schwab,
Greenhorn

Joined: Dec 07, 2004
Posts: 10
hi frendz..
I wana know how can i pass an array that is made in javascript..i.e i am calling a javascript method on submission of a jsp in which i made an array containing some values.Now i want to send this array to controller servlet.
Plz help asap.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

You cant.
What you can do is create a comma separated list of values from your javascript array as a string, pass it to the controller servlet where you again split it up into the original strings (use java.lang.String.split() )
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by Amtul Sb,:
Plz help asap.


Was that soon enough for you?

It is not a good idea to say ASAP or urgent when you past, it turns quite a few people off, who otherwise may be perfectly willing to help you.

Cheers.
[ December 09, 2004: Message edited by: Sonny Gill ]
Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi Amtul,
One more way is to create that many(as that of array size) hidden fields with same name and submit it to the controller servlet.


---------------
Kalai Selvan T.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

"Amtul Sb,",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bart Allen
Greenhorn

Joined: Dec 19, 2003
Posts: 21
You could call a javascript function upon submit that dynamically creates a multi select form input type and then loads it with values and selected attribute with values for each item in the array, and then when passed to the Servlet you can call request.getParameterValues("nameYouCalledDynamicSelect") to return a String[].


SCJP, SCWCD, SCBCD, SCJD
Amtul Schwab,
Greenhorn

Joined: Dec 07, 2004
Posts: 10
Thanx to u all..
well Gill i was really in much need of help at the time when i post here..

Thanx again..my problem is solved...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing array from jsp to servlet