必须要写数字签名,否则安全性没保障,这是JAVA的特点

解决方案 »

  1.   

    http://www.chinabs.net/java/default.asp?infoid=45
      

  2.   

    我的Action类
      class TypeAction
          extends AbstractAction {
        TypeAction(String name, int typeID) {
          super(name);
          this.typeID = typeID;
          String iconFileName = "Images/" + name + ".gif";
          if (new File(iconFileName).exists()) {
            putValue(SMALL_ICON, new ImageIcon(iconFileName));
          }
        }    TypeAction(String name, int typeID, String tooltip) {
          this(name, typeID);
          if (tooltip != null) { // If there is a tooltip
            putValue(SHORT_DESCRIPTION, tooltip); // ...squirrel it away
          }
        }    public void actionPerformed(ActionEvent e) {
    //...
        }    private int typeID;
      }
    toolbar中的调用:
        lineAction = new TypeAction("Line", LINE, "Draw lines");
        addToolBarButton(lineAction);高手看看呐,分数不是问题
      

  3.   

    //:Applet-发布有数字签名的Applet.txt/*
    时间:2003-4-17 21:35
    目的:发布有数字签名的Applet,扩展Applet的访问本地资源能力
    作者:[email protected]
    测试平台:Microsoft windows2000 server;j2sdk1.4.1_01文件清单(需要根据实际情况修正文件路径):
    f:\java\AppletJar.java
    f:\java\manifest.mf
    f:\java\appletjar.jar
    f:\java\mykeystore
    f:\java\web.html
    f:\java\XJTU\citi\AppletJar.class        
    f:\java\XJTU\citi\sonnet.xml
    */1、Applet源程序
    //: AppletJar.java
    // Very simple applet
    package xjtu.citi;
    import java.awt.*;
    import java.applet.*;
    import java.io.*;public class AppletJar extends Applet {
      public void paint(Graphics g) {    
        try{           ]
          //读取资源文件,访问服务器端的资源
         InputStream is = this.getClass().getResourceAsStream("sonnet.xml");
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
          byte[] buf = new byte[1024];
          int i;
          String str;
          do{
            i = is.read(buf);
            if (i != -1)
              baos.write(buf, 0, i);
            System.out.println(i);
          }while (i != -1);
          is.close();
          //由于sonnet.xml是文本文件,故转换成String方便使用,如进行XML解析
          str=new String(baos.toByteArray());
         g.drawString(str, 20, 30);
         
         //访问本地资源
         //读Applet用户的本地文件,当然f:/java/t.txt要存在,如果不存在会引发异常
         //实际操作时要有相应的改变
         BufferedReader in =new BufferedReader(new FileReader("f:/java/t.txt"));
          String s, s2 = new String();
          while((s = in.readLine())!= null)
            s2 += s + "\n";
          in.close();
         
         g.drawString(s2, 20, 60);
        }catch(Exception e){e.printStackTrace();}           
      }
    } ///:~
    2、manifest.mf:
    Manifest-Version: 1.0
    Main-Class: xjtu.citi.AppletJar
    Created-By: tangshancheng3、web.html
    <head><title>My Example Applet
    </title></head>
    <body>
    <applet code="xjtu.citi.AppletJar.class" 
            archive="appletjar.jar" 
            width=600 height=200>
    </applet>
    </body>4、编译、Jar
    F:\java>javac AppletJar.java -d .F:\java>jar cvfm appletjar.jar manifest.mf xjtu
    标明清单(manifest)
    增加:xjtu/(读入= 0) (写出= 0)(存储了 0%)
    增加:xjtu/citi/(读入= 0) (写出= 0)(存储了 0%)
    增加:xjtu/citi/AppletJar.class(读入= 1056) (写出= 669)(压缩了 36%)
    增加:xjtu/citi/sonnet.xml.bak(读入= 119) (写出= 101)(压缩了 15%)
    增加:xjtu/citi/sonnet.xml(读入= 115) (写出= 96)(压缩了 16%)5、数字签名
    a、如果没有数字证书,可以使用keytool生成一个自签名的数字证书
    F:\java>keytool -genkey -keystore mykeystore -alias tsc
    输入keystore密码:  yourpwd
    您的名字与姓氏是什么?
      [Unknown]:  shancheng tang
    您的组织单位名称是什么?
      [Unknown]:  xjtu
    您的组织名称是什么?
      [Unknown]:  cit
    您所在的城市或区域名称是什么?
      [Unknown]:  xi'an
    您所在的州或省份名称是什么?
      [Unknown]:  shanxi
    该单位的两字母国家代码是什么
      [Unknown]:  cn
    CN=shancheng tang, OU=xjtu, O=cit, L=xi'an, ST=shanxi, C=cn 正确吗?
      [否]:  y输入<mykey>的主密码
            (如果和 keystore 密码相同,按回车):
    b、这样会在当前路径下创建名为mykeystore的文件。c、如果你想察看一下刚才生成的myKeystore文件的内容,可以:
    F:\java>keytool -list -keystore mykeystore
    输入keystore密码:  yourpwdKeystore 类型: jks
    Keystore 提供者: SUN您的 keystore 包含 2 输入tsc, 2003-4-17, keyEntry,
    认证指纹 (MD5): FE:C0:E0:5D:DF:9C:EF:5D:40:4E:83:10:5B:14:F2:81
    mykey, 2003-4-17, keyEntry,
    认证指纹 (MD5): 58:1C:FB:B9:48:BC:AE:B3:DC:C5:EE:90:6A:95:A7:DFd、使用jarsigner签名
    F:\java>jarsigner -keystore mykeystore appletjar.jar tsc
    Enter Passphrase for keystore: yourpwd5、使用浏览器查看web.html
    如:http://192.168.2.6/xml/web2.html
    第一次访问时,要注意桌面右下的咖啡杯,他会弹出一个对话框,让你确认是否信任数字证书,
    为了演示,当然要选择信任。
      

  4.   

    终于解决问题了,原来关键问题不在于数字签名,因为我的applet的图标是保存在服务器上的,如果通过String iconFileName = "Images/" + name + ".gif";来获得图标文件的话,在客户端运行applet的时候在客户端是找不到这个文件夹的,我通过url定位服务器上的图标文件,就能显示了。