Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples

March 1, 2016 Categories: Applets. No Comments on Passing Parameters to Applets

In this article we will learn about passing parameters to applets using the param tag and retrieving the values of parameters using getParameter method.

 

Parameters specify extra information that can be passed to an applet from the HTML page. Parameters are specified using the HTML’s param tag.

 

Param Tag

The <param> tag is a sub tag of the <applet> tag. The <param> tag contains two attributes: name and value which are used to specify the name of the parameter and the value of the parameter respectively. For example, the param tags for passing name and age parameters looks as shown below:

<param name=”name” value=”Ramesh” />
<param name=”age” value=”25″ />

Now, these two parameters can be accessed in the applet program using the getParameter() method of the Applet class.

 

getParameter() Method

The getParameter() method of the Applet class can be used to retrieve the parameters passed from the HTML page. The syntax of getParameter() method is as follows:

String getParameter(String param-name)

 

Let’s look at a sample program which demonstrates the <param> HTML tag and the getParameter() method:

 

 

Output of the above program is as follows:

passing-parameters-to-applet

 

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up
Thank you for visiting startertutorials.com! If you like this website do share with your friends by clicking on the social icons available on the left hand side.

As the domain name is quite large to remember, use this short domain to visit this site. Short domain: stuts.me