java的安全机制限制了applet对客户端的操作一些操作,applet要想使用客户端的一些资源,那么就得授权认证签名什么的,这也就是增加了javaComm20-win32在applet中的使用难度。我可是折腾了好久才搞定的(不要被我这废话给吓着,有信心能搞定的)。
1)初始化一个web start(java plug-in)是非常重要的【http://www.javaeye.com/topic/61755】,一般情况下,你安装jdk的时刻就会帮你安装好的。在控制面板中找到"java plug-in“并且打开,找到”高级“指定所用的jre,你可以使用默认(C:/Program Files/Java/j2re1.4.2_08)的jre.
2)部署javaComm20-win32【 http://hgq0011.javaeye.com/blog/31508】。win32com.dll复制到java.home(也就是jre的路径)/bin下;把javax.comm.properties复制到java.home/lib下;把comm.jar添加到你classPath下。前面两个都是非常重要的。
3)在调用applet类中加入,
如果不这样的话, 就会抛出”Caught java.lang.NullPointerException: name can't be null while
loading driver com.sun.comm.Win32Driver“或者” C:/Program Files/Java/j2re1.4.2_08/bin/win32com.dll
already loaded in another classloader“ 的异常。
4)在JDK中对applet签名。
在C:/Program Files/Java/j2re1.4.2_08/lib/security/java.policy中增加如下内容
这样保证applet能使用任何资源。
1)初始化一个web start(java plug-in)是非常重要的【http://www.javaeye.com/topic/61755】,一般情况下,你安装jdk的时刻就会帮你安装好的。在控制面板中找到"java plug-in“并且打开,找到”高级“指定所用的jre,你可以使用默认(C:/Program Files/Java/j2re1.4.2_08)的jre.
2)部署javaComm20-win32【 http://hgq0011.javaeye.com/blog/31508】。win32com.dll复制到java.home(也就是jre的路径)/bin下;把javax.comm.properties复制到java.home/lib下;把comm.jar添加到你classPath下。前面两个都是非常重要的。
3)在调用applet类中加入,
public
class
AppletToComm
extends
JApplet
{
static { System.setSecurityManager(null); }//不使用安全管理器
.
public void callComm(){
//使用javaComm20-win32
}
}
static { System.setSecurityManager(null); }//不使用安全管理器
.
public void callComm(){
//使用javaComm20-win32
}
}
如果不这样的话, 就会抛出”Caught java.lang.NullPointerException: name can't be null while
loading driver com.sun.comm.Win32Driver“或者” C:/Program Files/Java/j2re1.4.2_08/bin/win32com.dll
already loaded in another classloader“ 的异常。
4)在JDK中对applet签名。
在C:/Program Files/Java/j2re1.4.2_08/lib/security/java.policy中增加如下内容
grant
{
permission java.security.AllPermission;
} ;
permission java.security.AllPermission;
} ;
这样保证applet能使用任何资源。