Solved

Passing data from applet back to html form ?

Posted on 1997-08-21
2
423 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
[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
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 “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 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

623 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