Solved

Passing data from applet back to html form ?

Posted on 1997-08-21
2
416 Views
Last Modified: 2008-02-26
I'm writing an applet that has a customized list .  Once
the user picks an item from the list, is there anyway to send this data back to the .html form that called it??

I see you can pass parameters from the .html to the applet, but can information be passed back?  I'm trying not to
program the entire form in java.

Thanks in advance.
0
Comment
Question by:mmanfra
2 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 100 total points
ID: 1225531

You can do this using JavaScript, but it will only work in
Netscape browsers.  To access a JavaScript method from java
you need to do:

      JSObject win = null;
        JSObject doc = null;

        try {
            win = JSObject.getWindow(this); //this is the Applet

              win.call("text.setText(\"New stuff\")");
        } catch (Exception e) {
            System.out.println("JavaScript error msg: " + e.getMessage());
            System.out.println("More error info: " + e.toString());
            e.printStackTrace();
        }


Don't forget to import:

import netscape.javascript.*;


You can call methods within Java from JavaScript like this:

document.MyApplet.stop()

or whatever method you need in place of stop.  

Remember you need to add the MAYSCRIPT tag to your Java applet
to make this work.  This will work in Navigator 3.0 and above.

There is no other way to access your HTML page directly from
Java or vice versa.

-Tony




0
 
LVL 2

Expert Comment

by:Philippe
ID: 1225532
This is how I send back information to a cgi-script on my server:

Note that the applet does not fill the form, but it calls the same cgi-script as the form does and passes the parameters directly to the cgi script.


qs is the query string which is appendend to the name of the cgi-sript.
cgiHome is the the location of the script (eg: www.home.com/cgi-bin/)


      try {
      String thisLine;
      String qs = "item="+item +"&price="+price;

      URL u = new URL(cgiHome + "results?" + qs);

      DataInputStream theHTML =
             new DataInputStream(u.openStream());
      while ((thisLine = theHTML.readLine()) != null) {
      parent.showStatus(thisLine);
      }
    }
    catch (Exception e) {
      System.err.println(e);
    }
 

Let me resubmit it as an answer if this is what you wanted.

 cheers,

    Philippe

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 73
mapAB Challlenge 35 85
groovy example issue 10 66
what is the difference between "sudo su" and "su - root" 6 70
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)
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…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

707 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

13 Experts available now in Live!

Get 1:1 Help Now