Solved

Java to submit forms on a web page

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse argument 14 60
Java Loop 6 60
xampp tool 12 49
eclipse apache tomcat admin console 52 97
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

770 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