Passing Javascript array to servlet

Discussion in 'Java' started by Garg, Feb 8, 2007.

  1. Garg

    Garg Guest

    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
     
    Garg, Feb 8, 2007
    #1
    1. Advertising

  2. On Feb 7, 10:41 pm, "Garg" <> 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
     
    Manish Pandit, Feb 8, 2007
    #2
    1. Advertising

  3. Garg

    Garg Guest

    Thanks Manish, for this valuable information.

    I will try this and let you about the result.

    thanks once again.

    Tarun
     
    Garg, Feb 10, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,423
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,900
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    2,017
    Jack Jia
    Apr 4, 2004
  4. Andrew Purser
    Replies:
    3
    Views:
    5,089
    Alex Kay
    Nov 4, 2004
  5. Garg

    Passing Javascript array to servlet

    Garg, Feb 8, 2007, in forum: Javascript
    Replies:
    2
    Views:
    198
    Frederik Vanderstraeten
    Feb 8, 2007
Loading...

Share This Page