• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

getting null value from getParameter() in Applet

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am doing a simple program for applet.


import java.applet.Applet;
import java.awt.Graphics;

@SuppressWarnings("serial")
public class ParameterExample extends Applet {
// We'll save the first HTM parameter as a String
String parameter1;
// the second one we will use as an integer
int parameter2;
// third one too
int parameter3;
// we'll add param2 to param2
int result;

public void init() {
// This method will get the specified parameter's value
// out of the HTML code that is calling the applet.
parameter1 = getParameter("param1");

// Since those are read as text we need to transform them
// to integers to be able to count with them.
parameter2 = Integer.parseInt(getParameter("param2"));
parameter3 = Integer.parseInt(getParameter("param3"));
result = parameter2 + parameter3;
}

public void paint(Graphics g) {
// Shows what was in the HTML param code.
g.drawString("Parameter 1 is: " + parameter1, 20, 20);
g.drawString("Parameter 2 is: " + parameter2, 20, 40);
g.drawString("Parameter 3 is: " + parameter3, 20, 60);
g.drawString("Parameter 2 + parameter 3 is: " + result, 20, 80);
}
}

HTML File---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<APPLET CODE="ParameterExample" WIDTH=200 HEIGHT=100>
<param name="param1" value="Hello">
<param name="param2" value="14">
<param name="param3" value="2">
</APPLET>
</body>
</html>



in the ParameterExample class I am getting the null in this line

parameter1 = getParameter("param1");

I am developing this program in eclipse.
 
Saloon Keeper
Posts: 6458
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you running the code? It works fine in appletviewer. Have you tried running it in a browser?
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running this code directly from eclipse.yeah its work fine in appletviewer.But I am getting the null value for param1.
 
Marshal
Posts: 25598
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you run it "directly from Eclipse", how do you provide the parameters and their values?
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the parameter and values I have put in html file.html file is in the same folder in eclipse.
 
Tim Moores
Saloon Keeper
Posts: 6458
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eshwin Sukhdeve wrote:yeah its work fine in appletviewer.But I am getting the null value for param1.


That sounds like a contradiction. Does it or does it not work in appletviewer or a browser?
 
Paul Clapham
Marshal
Posts: 25598
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eshwin Sukhdeve wrote:the parameter and values I have put in html file.html file is in the same folder in eclipse.



And when you run it in Eclipse, do you run the applet, or do you run the HTML file?
 
Greenhorn
Posts: 8
Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure the .class and .html files are in the same directory.

Edit this line

to

where you have ParameterExample instead of ParameterExample.class

Also, it would be good idea to catch exception ;)

 
Men call me Jim. Women look past me to this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic