aspose file tools*
The moose likes Applets and the fly likes getting null value from getParameter() in Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "getting null value from getParameter() in Applet" Watch "getting null value from getParameter() in Applet" New topic
Author

getting null value from getParameter() in Applet

Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 79
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.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
How are you running the code? It works fine in appletviewer. Have you tried running it in a browser?
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 79
I am running this code directly from eclipse.yeah its work fine in appletviewer.But I am getting the null value for param1.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18132
    
    8

And when you run it "directly from Eclipse", how do you provide the parameters and their values?
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 79
the parameter and values I have put in html file.html file is in the same folder in eclipse.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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
Bartender

Joined: Oct 14, 2005
Posts: 18132
    
    8

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?
Rene Ott
Greenhorn

Joined: Apr 20, 2012
Posts: 8

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 ;)

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting null value from getParameter() in Applet
 
Similar Threads
Can't accept parameters from an applet
Need help >>>
STRUTS 2 ERROR
NUllPointerException
form data not passing to servlet file