Applet访问本地资源

Applet

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

import javax.swing.SwingUtilities;

public class HelloApplet extends Applet {

public void paint(Graphics g) {
g.drawRect(0, 0, 499, 149);
g.drawString("Hello World", 5, 70);
}

/** * 通过applet调用本地的计算器 */
public void openApp() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String url = "C:\\WINDOWS\\system32\\calc.exe";
System.out.println("url=" + url);
try {
Runtime.getRuntime().exec(url);
} catch (IOException e) {
e.printStackTrace();
}
};
});
}
}


------------------------------------------------------------------------------

test.jsp


<HTML>
<HEAD>
<TITLE>A Simple Program </TITLE></HEAD>
<BODY>
<CENTER>
<APPLET CODE="HelloApplet.class" ARCHIVE = "helloApplet.jar" WIDTH="500" HEIGHT="150" id="helloApplet" name="helloApplet"> </APPLET>
<a href="#" onclick="openApp()">calc</a>
<script type="text/javascript">
function openApp(){
var helloApplet = document.helloApplet.openApp();

}
</script>
</CENTER>
</BODY>
</HTML>

--------------------------------------------------------

打jar包

jar -cvf helloApplet.jar *.*



生成密匙库

keytool -genkey -keystore hello.store -alias hello

这个命令用来产生一个密匙库,执行完毕后应该产生一个 hello.store的文件,这个名字你可以对它进行修改。另外在执行命令的时候还有提示你输入密匙库的密码,这里你一定要记住,否则后面要用的时候无法输入。输入密码后,它会提示你输入用户名,公司名等信息,这些都不是必须输入的,你可以直接回车跳过,最后问你输入是否正确,你可以输入y或n回答正确或错误。



导出证书

keytool -export -keystore hello.store -alias hello -file hello.cert



给jar包签名

jarsigner -keystore hello.store helloApple.jar hello

posted @ 2011-10-22 16:16  weep  阅读(273)  评论(0编辑  收藏  举报