Reputation: 97
I have saved the following:
import java.util.Map;
public class EnvMap {
public static void main (String[] args) {
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
System.out.format("%s=%s%n",
envName,
env.get(envName));
}
}
}
as a .java file and then typed
javac EnvMap.java
in a Windows Command prompt to compile it into a .class file. It compiled with no errors. I then typed
java EnvMap
in a Windows Command prompt and the script executed with no errors and showed me all the system information I was looking for.
Now I'm curious how to get this script to run in a webpage. I tried something like:
<html>
<body>
<APPLET CODE=EnvMap.class></APPLET>
</body>
</html>
This did not work.
Any tips are greatly appreciated. Thanks guys!
Upvotes: 0
Views: 5621
Reputation: 168835
Upvotes: 0
Reputation: 15844
First of all, your class have to extend java.applet.Applet
class.
I suggest you to look at some documentation first...
http://docs.oracle.com/javase/tutorial/deployment/applet/
Upvotes: 1
Reputation: 34367
Your class must extend Applet
class as below:
public class EnvMap extends Applet { //<--extends java.applet.Applet
public void paint(Graphics g) {
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
System.out.format("%s=%s%n",
envName,
env.get(envName));
}
}
}
Upvotes: 0
Reputation: 2292
What web server are you using?
What you really need is a server with a Java/servlet container that will allow you execute Java code as part of the web request processing. For example, Apache Tomcat.
(This is assuming you want to access environment variables on the server. If you want to access them on the client, well, I can't remember too well just how sandboxed an applet's runtime environment is, so you may be out of luck.)
Upvotes: 0