Solved

How do I pass variables between two applets on differnt html pages

Posted on 1998-08-05
5
503 Views
Last Modified: 2012-08-13
Hi,

I would like to know how to pass objects between two applets on differnt
html pages.

I tried using static variables and public static methods. It works only
for Netscape. It doesn't work for IE.

Can anyone help me on this.

Please cc your answers to sswami@krdl.org.sg

ThanX a lot
Cheers swamy
0
Comment
Question by:sswami
5 Comments
 

Expert Comment

by:theGrayPilgrim
ID: 1231417
A good way to do what you need is using Piped Streams.
One applet creates BOTH a PipedInputStream and a PipedOutputStream, and gives one end to the second applet.
The applet that has the Output end of the stream can start writing data into it, and the other applet, with the Input end,  can start reading.
In the book 'Hacking Java', which can be found online at www.mcp.com , there is a chapter called 'Inter-Applet Communication'. It has all the information you need, plus some examples.

-- Roy.
0
 

Author Comment

by:sswami
ID: 1231418
Hi Roy,

I am not sure about the Piped Stream beacuse of the nature of my problem.

I have an html page with an applet A.

The applet A uses url object to open another html page(appletcontext.showDocument()).
This html page contains an applet B.

How can I access a staic var C in Applet A which is set when A is started.

i

0
 
LVL 1

Expert Comment

by:dryang
ID: 1231419
Another way to do it is to use Sockets, but this is one hell of a workaround! May not be feasible, but here is my two cents worth...  :)

If applets are running on the same machine

1) Write a Server on the host machine which listens on two ports, one for applet A, another for applet B. (different port numbers of course)
2) program logic is as follows:
a) Applet A runs first. Opens connection with the Server. Writes the C value into the Server memory.
b) Applet A calls Applet B.
c) Applet B captures Applet A's IP address. B Opens connection with the Server. Reads the C value into the Applet.

Of course its more complex than that (synchronization problems and such), but that's the gist of it.

If the Applets are run from different machines, two Server programs must be run. One on Applet B's host and one on Applet A's host. This is neccesary as not to invoke any security exceptions.

have fun.
0
 

Accepted Solution

by:
tgoglia earned 50 total points
ID: 1231420
One possible solution that I've used is to use a server side script to generate the html page that the second applet is on, attaching a name/value pair to the URL string in the first applet.
   Say you want to pass a userName variable to the applet. Set the URL string to "www.domain.com/applet2.html?userName=" + userName.
   Retrieve the variable in the same way as if you had an html form field named userName and the write out the information needed to display the applet along with a parameter to pass the userName value on
0
 

Expert Comment

by:tgoglia
ID: 1231421
Another way to get the info from the name/value pairs into the second applet without using Serverside scripts-
 
 Use the Applet.getDocumentBase() to retrieve the URL of the page the applet is on, which will include the name/value pair you attached to the URL object from the first Applet.
 Note: neither solution will work with an object, but you can pass the information you need to recreate the object in the second applet.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question