T
trpost
I have a simple applet that uses the (Jakarta http client .jar files)
to get a status of a webpage. When I execute the code from a command
line after setting the classpath, it runs as expected. However when I
call the applet through a browser, it fails to load and I get an
exception java.lang.NullPointer exception. I am running this applet
using IE 6 SP2 on Windows XP running apache. I set the classpath that
worked for the commandline execution in the system environment
variables, but it doesn't work any different. Below is the exception
from the java console that I am getting:
java.lang.NoClassDefFoundError:
org/apache/commons/httpclient/HttpException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-11" java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Any ideas how to get my applet to work in a browser??
Below are my 2 files:
StatusCodeApplet.java:
import java.lang.*;
import java.io.*;
import java.awt.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import javax.swing.JApplet;
public class StatusCodeApplet extends JApplet
{
//Main method begins execution of java application
//public static void main(String args[])
//{
//String url = "http://eagledssdsdasdsaf";
//String result;
//System.out.println(url);
//result = getStatusCode(url);
//System.out.println(result);
//}
public static String getStatusCode(String urlWithParams) {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(urlWithParams);
String returnStatusCode = "NO_STATUS_CODE";
try {
// Execute the method.
int statusCode = client.executeMethod(method);
// method.getStatusLine();
returnStatusCode = Integer.valueOf(statusCode).toString();
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " +
e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
return returnStatusCode;
}
}
StatusCodeApplet.html:
<html>
<head>
<title>Http status code demo</title>
</head>
<body>
<script type="text/javascript">
function getStatusCode(uri)
{
return document.applets['statusApplet'].getStatusCode(uri);
}
</script>
<applet name="statusApplet" code="StatusCodeApplet.class" width="500"
height="500" archive="commons-httpclient-3.0.jar"></applet>
<script type="text/javascript">
//alert(getStatusCode('http://www.yahoo.com'));
</script>
</body>
</html>
The classpath I am using that works commandline is:
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_06
set PATH=%JAVA_HOME%\bin;%PATH%
set
CLASSPATH=.;C:\cowpack\htdocs\php\client\applet\Tst\commons-httpclient-3.0.jar;C:\cowpack\htdocs\php\client\applet\Tst\commons-logging.jar;C:\cowpack\htdocs\php\client\applet\Tst\commons-logging-api.jar;C:\cowpack\htdocs\php\client\applet\Tst\commons-codec-1.3.jar
The way I complied the java file was
javac StatusCodeApplet.java
The way I access the applet is:
http://localhost/php/client/applet/Tst/StatusCodeApplet.html
Any suggestions, or what am I doing wrong
Thanks
to get a status of a webpage. When I execute the code from a command
line after setting the classpath, it runs as expected. However when I
call the applet through a browser, it fails to load and I get an
exception java.lang.NullPointer exception. I am running this applet
using IE 6 SP2 on Windows XP running apache. I set the classpath that
worked for the commandline execution in the system environment
variables, but it doesn't work any different. Below is the exception
from the java console that I am getting:
java.lang.NoClassDefFoundError:
org/apache/commons/httpclient/HttpException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-11" java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Any ideas how to get my applet to work in a browser??
Below are my 2 files:
StatusCodeApplet.java:
import java.lang.*;
import java.io.*;
import java.awt.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import javax.swing.JApplet;
public class StatusCodeApplet extends JApplet
{
//Main method begins execution of java application
//public static void main(String args[])
//{
//String url = "http://eagledssdsdasdsaf";
//String result;
//System.out.println(url);
//result = getStatusCode(url);
//System.out.println(result);
//}
public static String getStatusCode(String urlWithParams) {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(urlWithParams);
String returnStatusCode = "NO_STATUS_CODE";
try {
// Execute the method.
int statusCode = client.executeMethod(method);
// method.getStatusLine();
returnStatusCode = Integer.valueOf(statusCode).toString();
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " +
e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
return returnStatusCode;
}
}
StatusCodeApplet.html:
<html>
<head>
<title>Http status code demo</title>
</head>
<body>
<script type="text/javascript">
function getStatusCode(uri)
{
return document.applets['statusApplet'].getStatusCode(uri);
}
</script>
<applet name="statusApplet" code="StatusCodeApplet.class" width="500"
height="500" archive="commons-httpclient-3.0.jar"></applet>
<script type="text/javascript">
//alert(getStatusCode('http://www.yahoo.com'));
</script>
</body>
</html>
The classpath I am using that works commandline is:
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_06
set PATH=%JAVA_HOME%\bin;%PATH%
set
CLASSPATH=.;C:\cowpack\htdocs\php\client\applet\Tst\commons-httpclient-3.0.jar;C:\cowpack\htdocs\php\client\applet\Tst\commons-logging.jar;C:\cowpack\htdocs\php\client\applet\Tst\commons-logging-api.jar;C:\cowpack\htdocs\php\client\applet\Tst\commons-codec-1.3.jar
The way I complied the java file was
javac StatusCodeApplet.java
The way I access the applet is:
http://localhost/php/client/applet/Tst/StatusCodeApplet.html
Any suggestions, or what am I doing wrong
Thanks