Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending an object to applet

 
Sri Latha
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have to send an Object to Applet.
Can anyone tell how to do this?


Thanks and Regards,
Latha
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does the object exist?
 
Sri Latha
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I have a collection of strings in a vector in main() of java program.And i tried to send the object with in the params of an applet.Able to retrieve only first element of vector object.

So is there any other way to send the object to applet.

Thanks and Regards,
Latha.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A param section like the following should work:

What does your param section look like?
 
Sri Latha
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Vector v = new Vector();
I have retrieved the result set from database.And i need to add that result set to vector
v.add(resultSetObjectValues);

<applet code=MultipleApplet.class width=400 height=350>
<PARAM name=vector value="+ v +">
</applet>

In the applet i am able to recieve only the first element of vector,though it contains many values.

Thanks and Regards,
Latha
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An HTML file is text; you can't embed Java objects in it. You'll need to iterate through the vector and add elements one by one, so that you end up with a param section like the one I showed above. The "length" parameter tells the applet how many parameters to read.
 
Sri Latha
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

Is there any way to do with Socket connection to send the vector Object to applet.And can iterate that vector in applet.


Thanks and Regards,
Latha
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, an applet can talk to a servlet using HTTP or serialization; see here for more information. (Note that serialization depends on both sides using the same JVM version, so unless you can dictate the JVM installed on the applet's users machines, this will likely not work.)

But what's wrong with writing parameters in a JSP? It's such an easy and straightforward approach, especially when compared with the alternatives.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic