Solved

Java to submit forms on a web page

Posted on 2000-04-06
2
549 Views
Last Modified: 2008-02-20
I have never used Java before, but may do so for a project I am working on at the moment. Can anybody tell me if you can use Java to submit a form to another target page (i.e. Java applet [a menu system] is in another frame).

Also, would there be any compatibility issues with various browsers that I should be aware of?

Hope you can help.

Cheers.
0
Comment
Question by:rhinosaur
2 Comments
 

Accepted Solution

by:
jpick earned 200 total points
Comment Utility
I'm not sure if I understand your questions, but this should help you out.

You can use the JSObject to communicate from Java to Javascript.  You can then write a javascript function to do the submit.  for example:

JAVA
-------

// Netscape imports
import netscape.javascript.*;
import netscape.plugin.*;

class MyClass extends Applet {
 
 ...

    public void submitForm()
   {
        try
          {
            m_window = JSObject.getWindow(this);
          }
      catch(Exception e)
          {
            e.printStackTrace();
                    }

      try
          {
            // submit form
            m_window.call("submitMyForm",null);
          }
        catch(Exception e)
          {
            e.printStackTrace();
          }

   }
}



Javascript
-------------

funtion submitMyForm()
{
      document.formname.submit();
}

You can find documentation on JSObject at http://developer.netscape.com.  This solution works for all 4.0 browsers and above.  Good Luck.

Jeff
0
 
LVL 1

Author Comment

by:rhinosaur
Comment Utility
Using "javac form.java" at the command prompt I get the following errors:

form.java:2: Package netscape.javascript not found in import"

form.java:3: Package netscape.javascript not found in import"

form.java:5: "Superclass Applet of class MyClass not found. class MyClass extends Applet {"

form.java:7: Type expected.

Also - will this work in IE browsers?

Do I need to include the following:

import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.event.*;

aswell?

Cheers,

Ben.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
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.

771 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

10 Experts available now in Live!

Get 1:1 Help Now