不要用applet直接连数据库。
你写个servlet,在applet和servlet之间进行通信就行了。
servlet负责从数据库取数据。
这样就不必考虑applet安全性带来的烦恼了。

解决方案 »

  1.   

    楼上兄弟说得没错,用servlet或者socket实现数据传输比较好实现数字签名过程C:\JDK\bin>keytool -genkey -alias acylas -keystore FrameWork.store
    输入keystore密码:  acylas98
    您的名字与姓氏是什么?
      [Unknown]:  acylas
    您的组织单位名称是什么?
      [Unknown]:  szu
    您的组织名称是什么?
      [Unknown]:  acylas
    您所在的城市或区域名称是什么?
      [Unknown]:  sz
    您所在的州或省份名称是什么?
      [Unknown]:  cn
    该单位的两字母国家代码是什么
      [Unknown]:  cn
    CN=acylas, OU=szu, O=acylas, L=sz, ST=cn, C=cn 正确吗?
      [否]:  y输入acylas的主密码 acylas20
            (如果和 keystore 密码相同,按回车)
    C:\JDK\bin>jarsigner -keystore FrameWork.store -storepass acylas98 FrameWork.jar acylasC:\JDK\bin>keytool -export -alias acylas -file FrameWork.cer -keystore FrameWork.s
    tore
    输入keystore密码:  acylas20注:1.经过这两步后生成的jar文件就实现了数字签名
        2.以后每次重新生成jar,只需要执行第二步
      

  2.   

    用JDK1.4开发数字签名的Swing Applet
    1) 写代码
    我们准备开发一个既是APPLET又是APPLICATION的程序,使得程序既能在浏览器中运行,直接双击JAR文件也可以运行。
    程序界面采用了SWING控件,使用JInternalFrame来展示通过文件选择框指定的GIF或JPG图片。
    程序文件:Jtest.java, ExampleFileFilter.java。
    程序编译完成后,假定所有的class文件位于d:\myapplet下面。2)生成jar文件
    创建一个manifest.mf文件位于d:\myapplet下面,文件内容:
    Manifest-Version: 1.0
    Main-Class: Jtest
    Created-By: 1.4.0-beta2 (Sun Microsystems Inc.)
    执行命令:jar cvfm manifest.mf Jtest.jar *.class
             jar cvfm Draw.jar manifest.mf .
    则生成Jtest.jar文件,此时双击该文件即能以application的形式运行。3)准备HTML文件
    创建一个HTML文件Jtest.htm, 位于d:\myapplet下面,文件内容:
    <HTML>
    <HEAD>
    </HEAD>
    <BODY >
    <CENTER>
    <APPLET code= "Jtest.class"  codebase= "."  archive ="Jtest.jar"  width= 0  height="0">
    </APPLET>
    </CENTER>
    </BODY>
    </HTML>
    然后需要使用JDK1.4附带的HtmlConverter.exe转换Jtest.htm,使得浏览器能自动下载SUN的JRE1.4。
    执行命令:htmlconverter Jtest.htm,生成的Jtest.htm自动包含了下载插件的代码。4) 数字签名
    首先是生成公/私密钥对:
    keytool –genkey –alias yourname –keypass yourpassword
    其中的yourname为密钥的别名,yourpassword为密码,按照提示输入签名信息。然后执行:如果需要导出证书,则执行命令:
    keytool –export –alias yourname –file yourname.cer
    生成的yourname.cer即为证书文件。不过签名APPLET可以不需要这一步。然后就是对JAR文件进行签名:
    jarsigner Jtest.jar yourname
    需要输入你在上面步骤中提供的密码。至此签名已经成功。无论是直接打开Jtest.htm文件还是通过服务器下载Jtest.htm和Jtest.jar执行applet,首先会弹出一个提示框,如果用户点接受,则APPLET可以访问本地文件系统以及做其它事情,如果点拒绝则不能访问本地文件系统。当然,如果点总是接受,则以后运行同一个APPLET的时候不会出现提示,自动拥有权限。
      

  3.   

    在java中的 applet 的认证和签名 确实麻烦。。
     java.sun.com  的tutorial 上有用apple 在本地写一个文件的例子:
     http://java.sun.com/docs/books/tutorial/security1.2/tour1/
     但只能用AppletViewer 可以看:
     appletviewer http://java.sun.com/docs/books/tutorial/security1.2/tour1/example-1dot2/WriteFile.html
      又在[阿费]的帮助下找到可以用ie or Nescape 查看你的applet 的例子:
      http://www.intelligentsearch.org/namesearch_from_java.htm#_Toc490550108大致过程如下::服务器端:
     
    1。 Compile the java classes --写applet并编译。
        javac *.class
    2.   Place the class files in a JAR file    --打包:
        jar cvf  yourjarname.jar  yourdir/*.class
        1). Create a Keystore and Keys for signing the JAR file 
            keytool –genkey –keystore ist.keystore –alias IST
        2). Sign the JAR file                  --对jar 签名
            jarsigner –keystore ist.keystore ist.jar IST
        3). Create the Public Key Certificate  --创建公钥
            keytool –export –keystore ist.keystore –alias IST –file IstPubKey.cert
    客户端:   1。Import the Public Key Certificate --导入公钥
          keytool –import –alias IST –file IstPubKey.cert –keystore client.store
       2。Modifing a policy file  --修改 policy文件
       3。 Run the applet   --运行applet
       !!! 这还只能用Applet viewer 查看你的applet 
       
    用ie访问:
    First, the <APPLET> tag will not be able to activate the Java Plug-in for use in IE. This tag should be substituted by the <OBJECT> tag
     ---由于IE 的java Plug-in 不能被<APPLET>标签激活。你还要将他换成<OBJECT>标签。 these changes to the HTML file can also be done with the help of HTMLConverter. You can go to download this software from http://java.sun.com/products/plugin/index.html. 
    ---- 这样你还要去下一个HTMLConverter
    ---- 将经过转换的html 和 class 文件copy 到你的服务器上。
    -- 好了。终于可以享受一下成果了。
         用ie 访问:http://yourserver: youreport/WriteFile.html
         还不行?? 
         --IE 还要下载Plug-in 才能执行,
         在1小时加26分46秒后:
         kao ,终于在本地写了一个文件。