RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Oct 4, 2005



Building the Right Environment to Support AI, Machine Learning and Deep Learning

How to Pass Parameters from a Java Applet to an HTML File

Sometimes you need to pass parameters from an applet to an HTML file. For instance, you may want to detect, using an applet, the IP address of the viewer when they are trying to access your page and send them to a HTML page that will dynamically use it.

applet_test.java: This is the sample Java applet that returns the hostname of the machine and the IP address associated with that hostname.

--- applet_test.java ---
import java.applet.Applet;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class applet_test extends Applet {
	private InetAddress addr = null;
	public void init() {
		try {
			addr = InetAddress.getLocalHost();
		catch (UnknownHostException e) {
	public InetAddress getLHost() {
		return addr;
test.html: The sample HTML file test.html calls a Java applet (applet_test.class) and gets the getLHost() parameter from this applet:

--- test.html ---
<APPLET CODE=applet_test.class Width=0 Height=0></APPLET>
<script type="text/javascript">
Sergejs Svitnevs
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date