By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,608 Members | 1,925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,608 IT Pros & Developers. It's quick & easy.

Passing arrays to Java from JavaScript

P: n/a
This may be more of a Java question, but I feel that JavaScript experts
may be more qualified to help me find a solution.

In short: is it possible to call a Java method from JavaScript, passing
as an argument a JavaScript array (in my case, an array of doubles)?

Supposing I have array x containing only doubles, I have tried:
document.MyApplet.myMethod(x);

But the method only ever seems to receive "null" as an argument.
Conversely, if I try this with a String, or a single character, or
almost anything else, there isn't a problem. Any ideas?
Jul 20 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Eric Capps" <no@thanks.comwrote in message
news:e9**********@geraldo.cc.utexas.edu...
This may be more of a Java question, but I feel that JavaScript experts
may be more qualified to help me find a solution.

In short: is it possible to call a Java method from JavaScript, passing as
an argument a JavaScript array (in my case, an array of doubles)?

Supposing I have array x containing only doubles, I have tried:
document.MyApplet.myMethod(x);

But the method only ever seems to receive "null" as an argument.
Conversely, if I try this with a String, or a single character, or almost
anything else, there isn't a problem. Any ideas?
There are definately ways to pass structured data via XML. These are most
often used to pass structured date from client-side code to server-side code
(HTTP being text only) - I'm assuming that you're talking about a
client-side exchange (from script to an applet) however - is that right?

In any case they may still help. All of them work in essentially the same
way: they convert structured data (objects, arrays, etc) into a plain-text
(string) representation for transfer.

Here are several common options:

WDDX is an oldie but a goodie with good JavaScript and Java support:
http://www.openwddx.org/
(I've built a more up-to-date JavaScript parser for WDDX here:
http://www.depressedpress.com/Conten...WDDX/Index.cfm
The original is getting a little long in the tooth.)

JSON isn't XML which makes it the least verbose option here but it falls
down a bit when trying to maintain data typing such as seprating dates from
strings and so forth. Still, since JavaScript and Java share much of their
literal notations it may be the best bet:
http://www.json.org/

XML-RPC is well supported (although I find it very verbose):
http://www.xmlrpc.com/

I've built my own dialect which, unfortunately lacks Java support (care to
build it?) but attempts to address my concerns with other options:
http://www.depressedpress.com/Conten...ODEL/Index.cfm

Jim Davis
Jul 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.