HOWTO: Getting an Applet to Submit Information
ID: Q177161
|
The information in this article applies to:
-
Microsoft SDK for Java, versions 1.51, 2.0, 2.01, 2.02, 3.0, 3.1, 3.2
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.
- 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;
}
- Create a Web page with an applet inside your form.
- Create a hidden field in the <FORM>, where your applet will submit its
data.
- Write a script function, like processApplet() in the example below, to
populate the hidden field by calling public functions of your applet.
- 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,
please see the following pages 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 kbnokeyword kbSDKJava300 kbVJ kbSDKJava310 kbSDKJava320
Version : WINDOWS:1.51,2.0,2.01,2.02,3.0,3.1,3.2
Platform : WINDOWS
Issue type : kbhowto