Solved

Java to submit forms on a web page

Posted on 2000-04-06
2
554 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
ID: 2690543
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
ID: 2881123
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

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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.

735 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