Digital signature for Java Applet and Java Web Start
We know that the Java Applet and Java Web Start programs are subject to secure restrictions, such as unavailable access to the local file system, and cannot access the network at will. This article will demonstrate how to do digital signatures for the code, let customers choose whether to trust your signature while running so that your program has more permissions. Here we don't plan to purchase a certificate.
My computer environment is as follows: Windows2000 Professional SP3Sun JDK1.4.0ie6.0java_home, Path, ClassPath, etc. Environment variables have been set
Client requirements: The client browser needs to install the Java plugin, where the Java plugin here is installed together when installing JDK. If the client doesn't need to do Java development, you can download the Sun's website to download JRE to the client installation. Next, let's take a look at this applet, it only has a button, click this button to create a file locally, if successful, pop up a dialog box display success message, if an exception (safe exception or IO exception), also pop up a display Error dialog. The source file is as follows:
Source file test / Testapplet.java
Package test;
Import java.applet. *; import java.io. *;
Import java.awt.event. *; import javax.swing. *;
public class TestApplet extends Applet {public void init () {JButton button = new JButton ( "Create a file"); button.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent evt) {File file = new File ( "c : //a.txt "); try {file.createnewfile (); JOPANE.SHOWMESSAGEDIALOG (NULL," Successfully created file c: //a.txt "," message ", joptionpane.information_message);} catch (Exception EX ) {JOPANE.SHOWMESSAGEDIALOG (NULL, EX.GETMESSAGE (), "Error", JOPANE.ERROR_MESSAGE);}}}; add (button);}}
Compile this appletjavac test / testapplet.java in the parent catalog with the test catalog
Package, build Test.jar file jar -cvf test.jar test
The following is the HTML page using Applet Test.html
HTML Test Page title> < / HEVA Enabled Blowser.