Solved

Passing data from applet back to html form ?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 36
Opening PDF on button click and fill new document 2 53
jboss 7.1 start up error 1 60
JDBC performance 8 28
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

685 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