Microsoft KB Archive/251962

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 13:52, 21 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base

Article ID: 251962

Article Last Modified on 6/14/2006


  • Microsoft Java Virtual Machine
  • Microsoft Visual J++ 6.0 Standard Edition

This article was previously published under Q251962


This article describes how to obtain information from an applet and post it to an HTML form so that the data can be submitted to a Web server.


This sample creates an applet that interacts with Microsoft JScript to process the user's data. The sample also uses hidden form fields so that the user only interfaces with the applet.

Steps to Create Solution

  1. Create an applet that contains a public function, which returns the information that you want to submit. In the following sample code, an image reference number is returned:

    import java.applet.*;
    public class myApplet extends Applet
       int m_nCurrImage = 6;
       public void init()
       public int getCurrentImage()
          return m_nCurrImage;
  2. Create a Web page with an applet inside the form, and hide the field in the form where your applet submits its data.
  3. Create a script function called processApplet that populates the hidden field after it receives the data from the applet.
  4. Set the onClick function of the form's submit button to execute the processApplet script function.
  5. The preceding steps should return the following code:

    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
       <form action="/scripts/info.dll" method=GET name="myForm" >
       <applet code=myApplet.class id=myapplet width=320 height=240  VIEWASTEXT>
       <input type=hidden name="appletImage">
       <script language=JScript>
          function processApplet()
             parent.myForm.appletImage.value = myapplet.getCurrentImage();
             alert("Sent to form: Image Name: " +
                   parent.myForm.Picture.value +
                   " Image Number: " +
       <p>Image Name:<input type=text name="Picture"></p>
       <input type=submit value="Send following picture."
              language="JScript" onClick="processApplet();">

    Note The form's action attribute assumes that Info.dll resides on the server, but this is not necessary for the purpose of this sample.

  6. After you name the image, press the button to process the form. A dialog box displays the image name and the number that is being submitted with the form.


For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Keywords: kbhowto KB251962