Solved

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

Posted on 1998-08-05
5
500 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now