Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 1998-08-05
5
Medium Priority
?
515 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:
Suggested Courses

972 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