Solved

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

Posted on 1998-08-05
5
506 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 67
import as existing maven project 3 77
learn programming 8 94
Github api to fetch the number of collaborators in a git repo 1 68
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

734 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