Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing array from jsp to servlet

 
Amtul Schwab,
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Bart Allen
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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[].
 
Amtul Schwab,
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic