Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing data from applet back to html form ?

Posted on 1997-08-21
2
Medium Priority
?
424 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
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 …
Suggested Courses

715 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