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
Solved

Passing data from applet back to html form ?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 60
MySqlDump not dumping triggers 1 43
Facing this issue for maven proxy setting 2 19
swing controls 2 15
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)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

789 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