HOWTO: Getting an Applet to Submit Information

Last reviewed: January 29, 1998
Article ID: Q177161
The information in this article applies to:
  • SDK for Java, versions 1.51, 2.0, 2.01

SUMMARY

When I have an applet in a <FORM> it doesn't submit any information to the server. How can I get the applet to submit its information?

MORE INFORMATION

The applet doesn't submit any information because the information a user would want to submit is specific to the applet. For example, an applet that shows images may want to submit the currently displayed image number, while an applet that displays a clock may want to submit the GMT time. It is up to the programmer to write the methods to submit the applet. The five steps below show one way you might implement submitting an applet.

  1. Create an applet with a public function that returns the information you want to submit. (For the first example above, you would return the image number.)

          public int getCurrentImage() {
    
             return m_nCurrImage;
          }
    
    

  2. Create a Web page with an applet inside your form.

  3. Create a hidden field in the <FORM>, where your applet will submit its data.

  4. Write a script function, like processApplet() in the example below, to populate the hidden field by calling public functions of your applet.

  5. Set your submit button's onClick function to call the script function you wrote in step 4.

    Here is the finished product:

          <form action="/scripts/info.dll" method=GET name="myForm" >
          <applet code=AppletInForm.class id=myapplet width=320 height=240 >
          </applet>
          <input type=hidden name="appletImage">
          <script language=JScript>
    
             function processApplet()
             {
                parent.myForm.appletImage.value=document.myForm.myapplet.
                getCurrentImage();
                alert("Sending form: image="+parent.myForm.appletImage.value+"
                user="+parent.myForm.Username.value);
             }
             </script>
             <br>
             Username:<input type=text name="Username"><br>
             <input type=submit value="Please send me the above picture."
              language="JScript" onClick="processApplet();">
             </form>
    
    

REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/


Additional query words: submit applet information

Keywords : kbcode VJMisc
Technology : kbInetDev internet
Version : WINDOWS:1.51,2.0,2.01
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.