#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    22
    Rep Power
    0

    Question javascript array to java


    Is it possible to pass an array in javascript to java or a java applet?

    thanks
  2. #2
  3. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Being a Java newbie, I can't give you a definitive on how to pass the array to a client-side applet, although it should be possible.

    As for passing it to something server-side there are only a couple ways: in a GET request on the query string or in a POST. No matter what, you will have to flatten the array with some method or other, to convert it into a text string that can be parsed on the other end.

    I personally favor using hidden form elements and posting the data, because otherwise you have to worry about urlencoding your query string. You could just use javascript itself to write a series of hidden text inputs and then submit the form, so all your form handler has to do is pick up the variables.

    Let's say the array is named "myarray":

    Code:
    <script language="Javascript">
    
    document.writeln("<form name=\"myform\" method=\"POST\" action=\"myserver/myhandler.jsp\">")
    
    for(i = 0; i < myarray.length; i++){
      document.writeln("<input type=\"hidden\" name=\"myarray[" + i + "]\" value=\"" + myarray[i] + "\">")
      }
    
    document.writeln("</form>")
    document.myform.submit()
    
    </script>
    I know this is clunky and "low-tech" but it will work, and has the benefit of working for any server-side platform that can handle forms.
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    22
    Rep Power
    0
    thanks, I will give this a try

IMN logo majestic logo threadwatch logo seochat tools logo