• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Returning byte array to JavaScript from Java applet

 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you convert the byte array to a String and return that?
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ..
 
reply
    Bookmark Topic Watch Topic
  • New Topic