Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Passing Javascript array to servlet

Reply
Thread Tools

Passing Javascript array to servlet

 
 
Garg
Guest
Posts: n/a
 
      02-08-2007
Hi All,

I am facing one problem if you are having any solution please tell me.

I have to pass an array from javascript to servlet. for this i created
one array and pass that through submitting the form with post method
and i am using request.getParameterValues to get that array. But i am
getting values in the first position of that array and that also comma
separated so that also of no use for me.

Is there any way to pass the value to the Servlet?

Thanks
Tarun Garg

 
Reply With Quote
 
 
 
 
Manish Pandit
Guest
Posts: n/a
 
      02-08-2007
On Feb 7, 10:41 pm, "Garg" <(E-Mail Removed)> wrote:
> Hi All,
>
> I am facing one problem if you are having any solution please tell me.
>
> I have to pass an array from javascript to servlet. for this i created
> one array and pass that through submitting the form with post method
> and i am using request.getParameterValues to get that array. But i am
> getting values in the first position of that array and that also comma
> separated so that also of no use for me.
>
> Is there any way to pass the value to the Servlet?
>
> Thanks
> Tarun Garg


You cannot pass arrays from a form to a servlet. It has to be Strings,
or Binary data (multipart requests). Instead of creating an array, you
can set multiple values for the parameter, and use
getParameterValues( ) to get all values as an array. This is pretty
common for checkbox groups, like:

<FORM>
<P>Check all the colors you like</P>
<LABEL><INPUT TYPE="checkbox" NAME="favcolor" VALUE="red">Red</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="favcolor" VALUE="green">Green</
LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="favcolor" VALUE="blue">Blue</
LABEL>
</FORM>

As you can see, the name is same (favcolor) with different values. If
Red and Green are selected, the query string will look something like ?
favcolor=red&favcolor=green.

-cheers,
Manish

 
Reply With Quote
 
 
 
 
Garg
Guest
Posts: n/a
 
      02-10-2007
Thanks Manish, for this valuable information.

I will try this and let you about the result.

thanks once again.

Tarun

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Javascript array to servlet Garg Javascript 2 02-08-2007 10:08 AM
Passing Servlet Context to a non servlet object. Andrew Purser Java 3 11-04-2004 02:54 AM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
Tomcat: POST from one servlet or internal class to another servlet Sean Clarke Java 1 01-07-2004 02:22 PM
how to get my servlet configuration before the servlet is initialised Andy Fish Java 4 12-17-2003 09:47 PM



Advertisments