Solved

Java to submit forms on a web page

Posted on 2000-04-06
2
557 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
[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
 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

617 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