• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Returning byte array to JavaScript from Java applet

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to find an answer for this.

My javascript is able to receive string and java primitive types from my applet. However, if the applet method returns a java array then the javaScript variable always gets no value.

Assuming only the latest Internet Explorer version (7.0 and up) is used,
is it possible to have an applet method that returns a java array to javaScript? If so, could someone please provide a simple example. Many thanks.

Jesus
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you convert the byte array to a String and return that?
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am passing an array of bytes, in both ways:

java to javascript
javascript to java

I am not sure how to do it accurately using 'String' that you mentioned, other than this strategy below:

1. Convert each byte into an int
e.g. 'a' to '97'

2. That way, in #1, I cover all scenarios, from -128 to +127

3. I concatenated all into a single string, with a delimiter like ':'.
e.g. 'a','b','c' to '97:98:99'

4. Pass it, and receiver easily recreates a 100% copy of the array

Java and javascript as far as I know, doesnt have a standard that browsers or java engines are supposed to comply with, with regards to data conversion between them, on precise things like byte.

Let me know if you know any 100% reliable, easier way than what I designed?
[ October 17, 2008: Message edited by: Jesus Angeles ]
 
vanlalhmangaiha khiangte
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can get the JAVA array in the java part ..
Then in the javascript you can create your custom objects as below ..



You can decide how you want to create your custom objects ...
Trying to find a good tutorial but couldn't find it ...

Hope this helps ..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic