ch09.html

来自「java2高级编程」· HTML 代码 · 共 985 行 · 第 1/3 页

HTML
985
字号
<LI CLASS="NLS"><A NAME="pgfId-1087593"></A>Start the control panel applet by loading the <EM CLASS="CODE">/opt/NSCPcom/j2pi/ControlPanel.html</EM> file, which contains the <EM CLASS="CODE">Control Panel</EM> applet. If the <EM CLASS="CODE">Control Panel</EM> applet starts, the installation is correct and complete. The control panel applet lets you change the default settings used by Java Plug-In at startup. All applets running inside Java Plug-In use these settings. </LI></OL><P CLASS="Body"><A NAME="pgfId-1087594"></A>You can also run the <EM CLASS="CODE">Control Panel</EM> as an application like this:</P><PRE CLASS="CODE"><A NAME="pgfId-1087595"></A>cd /opt/NSCPcom/j2piControlPanel &amp;</PRE></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087596"></A>Install the HTML Converter</H5><P CLASS="Body"><A NAME="pgfId-1087598"></A><A NAME="marker-1087597"></A>Your browser will not automatically use the Java Plug-In when you load an HTML file with an applet. You have to download and run the Java Plug-In HTML Converter on the HTML page that invokes the applet to direct the applet to run using the plug-in instead of the browser's default run time. </P><P CLASS="Body"><A NAME="pgfId-1087599"></A>Unzip the Java Plug-In HTML Converter download: </P><PRE CLASS="CODE"><A NAME="pgfId-1087600"></A>unzip htmlconv12.zip</PRE><P CLASS="Body"><A NAME="pgfId-1087602"></A>Add the <EM CLASS="CODE">HTMLConverter.java</EM> program or its directory to your <EM CLASS="CODE">CLASSPATH</EM>. <EM CLASS="A"></EM><A NAME="security"></A></P></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087603"></A>Security Policy File</H5><P CLASS="Body"><A NAME="pgfId-1087606"></A><A NAME="marker-1087604"></A><A NAME="marker-1087605"></A>In the Java 2 Platform, applets are restricted to a sandbox-like environment and need permission to access system resources outside their restricted environment. Applets are restricted to access operations within their local directory. All other access operations require permission. </P><P CLASS="Body"><A NAME="pgfId-1087612"></A><EM CLASS="Bold">Types of Policy Files. </EM><A NAME="marker-1087607"></A><A NAME="marker-1087608"></A><A NAME="marker-1087609"></A><A NAME="marker-1087610"></A><A NAME="marker-1087611"></A>You need a policy file to grant access permissions to the <EM CLASS="CODE">Administration</EM> applet. If the applet runs on a disk other than the disk where the browser is running, the applet will also need to be signed. See Signed Applets (Chapter 10) for information on signing and deploying applets. </P><P CLASS="Body"><A NAME="pgfId-1087613"></A>There are three kinds of policy files: system, user, and program. The system policy file is located in <EM CLASS="CODE">jdk1.2/jre/lib/security/java.policy</EM> or <EM CLASS="CODE">jre1.2/lib/security/java.policy</EM> and contains permissions for everyone on the system. </P><P CLASS="Body"><A NAME="pgfId-1087614"></A>The user policy file is located in the user's home directory. The user policy file provides a way to give certain users additional permissions over those granted to everyone on the system. The permissions in the system file are combined with the permissions in the user file. </P><P CLASS="Body"><A NAME="pgfId-1087615"></A>A program policy file can be located anywhere. It is specifically named when an application is invoked with the <EM CLASS="CODE">java</EM> interpreter command or when an applet is invoked with applet viewer. When an application or applet is invoked with a specific policy file, the permissions in that policy file take the place of (are not combined with) permissions specified in the system or user policy file. Program policy files are used for program testing or intranet deployment of applets and applications. </P><P CLASS="Body"><A NAME="pgfId-1087617"></A><EM CLASS="Bold">Install the Policy File. </EM><A NAME="marker-1087616"></A>Place the security policy file in your home directory and name it <EM CLASS="CODE">.java.policy</EM>. When the applet tries to perform an action that requires a policy file with a permission, the policy file is loaded from this directory and remains in effect until you exit and restart the browser. If an applet tries to perform an access operation without the right permission, it quietly quits without raising either an applet or browser error.</P><P CLASS="Body"><A NAME="pgfId-1087618"></A><EM CLASS="Bold">Change the Name or Location. </EM>You can change the name and/or location of the default system or user policy file. Edit the <EM CLASS="CODE">jdk1.2/jre/lib/security/java.security</EM> or <EM CLASS="CODE">jre1.2/lib/security/java.security</EM> file and add a third entry specifying the name and location of an alternative policy file. </P><PRE CLASS="CODE"><A NAME="pgfId-1087619"></A>policy.url.1=file:${java.home}/lib/security/java.policypolicy.url.2=file:${user.home}/.java.policypolicy.url.3=file:/&lt;mypolicyfile path and name&gt;</PRE></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087620"></A>Run the Administration Applet</H5><P CLASS="Body"><A NAME="pgfId-1087621"></A>Copy the JAR file with the <EM CLASS="CODE">Administration</EM> applet and policy file to its final location. In this example, that location is the <EM CLASS="CODE">/home/zelda/public_html</EM> directory. Next, extract the applet class file and policy file from the JAR file: </P><PRE CLASS="CODE"><A NAME="pgfId-1087622"></A>cp admin.jar /home/zelda/public_html/jar xvf applet.jar</PRE><P CLASS="Body"><A NAME="pgfId-1087623"></A>The extraction places the policy file under the <EM CLASS="CODE">public_html</EM> directory and creates an <EM CLASS="CODE">admin</EM> directory under the <EM CLASS="CODE">public_html</EM> directory with the applet class file in it. Make sure the policy file in the <EM CLASS="CODE">public_html</EM> directory is named <EM CLASS="CODE">.java.policy</EM> and copy it to your home directory. </P><P CLASS="Body"><A NAME="pgfId-1087624"></A>In the <EM CLASS="CODE">public_html</EM> directory, create an HTML file that invokes the <EM CLASS="CODE">Administration</EM> applet class. Be sure to include the <EM CLASS="CODE">admin</EM> directory when you specify the applet class to the <EM CLASS="CODE">CODE</EM> option. Note that when using Java Plug-In, you cannot have the browser load the class file from the JAR file. </P><PRE CLASS="CODE"><A NAME="pgfId-1087625"></A>&lt;HTML&gt;&lt;BODY&gt;&lt;APPLET CODE=admin/AdminApplet.class  WIDTH=550  HEIGHT=150&gt;&lt;/APPLET&gt;&lt;/BODY&gt;&lt;/HTML&gt;</PRE><PRE CLASS="CODE"><A NAME="pgfId-1087626"></A><EM CLASS="Bold">Start the HTML Converter.  </EM>java HTMLConverter</PRE><P CLASS="Body"><A NAME="pgfId-1087627"></A>In the HTML Converter graphical user interface shown in Figure 9.2, select <EM CLASS="CODE">One File</EM>, specify the path to the <EM CLASS="CODE">admin.html</EM> file, and click the <EM CLASS="CODE">Convert</EM> button. After the conversion completes, load the <EM CLASS="CODE">admin.html</EM> file in your browser. </P><DIV><H6 CLASS="FC"><A NAME="pgfId-1087632"></A>Figure 9.2 <A NAME="82296"></A>HTML Converter user interface</H6><DIV><IMG SRC="CH09-2.gif"></DIV></DIV></DIV></DIV><DIV><H4 CLASS="A"><A NAME="pgfId-1087634"></A><A NAME="64121"></A>Deploy to Win32 Platform</H4><P CLASS="Body"><A NAME="pgfId-1087637"></A><A NAME="marker-1087635"></A><A NAME="marker-1087636"></A>On Win32 platforms, Java Plug-In software is bundled with the Java 2 Runtime Environment. Java Plug-In lets Web browsers use the Java 2 Runtime Environment to run 1.2-based applets and JavaBeans components instead of the Web browser's default virtual machine. The Java Plug-In works with Netscape Communicator and Microsoft Internet Explorer. </P><P CLASS="Body"><A NAME="pgfId-1087638"></A>This section explains how to install Java Plug-In with Netscape Communicator on the Win32 operating system.</P><DIV><H5 CLASS="B"><A NAME="pgfId-1087639"></A>Get Downloads</H5><P CLASS="Body"><A NAME="pgfId-1087640"></A>To install and use the Java Runtime Environment with Java Plug-In, you need the following downloads. Put the downloads in a temporary directory. </P><UL><LI CLASS="BL"><A NAME="pgfId-1087641"></A>Java Runtime Environment with Java Plug-In for Win32 Platforms.</LI><LI CLASS="BL"><A NAME="pgfId-1087642"></A>Java Plug-In HTML Converter</LI></UL></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087643"></A>Install JRE with Java Plug-In</H5><P CLASS="Body"><A NAME="pgfId-1087645"></A><A NAME="marker-1087644"></A>An optionally installable version of the Java 2 Runtime Environment with Java Plug-In is included with the J<EM CLASS="A">ava 2 SDK</EM> download. You can also download and install Java 2 Runtime Environment with Java Plug-In <EM CLASS="A">separately (</EM><EM CLASS="URL-Footnote">http://java.sun.com/products/jdk/1.2/jre/download-windows.html</EM><EM CLASS="A">)</EM>. </P><P CLASS="Body"><A NAME="pgfId-1087646"></A>Either way, install the Java 2 Runtime Environment with Java Plug-In by double-clicking its icon and following the installation instructions. When the installation completes, you will see the Java Plug-In control panel on your Windows <EM CLASS="CODE">Start</EM> menu under <EM CLASS="CODE">Programs</EM>.</P></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087647"></A>Install the HTML Converter</H5><P CLASS="Body"><A NAME="pgfId-1087649"></A><A NAME="marker-1087648"></A>Your browser will not automatically use the Java Plug-In when you load an HTML file with an applet. You have to download and run the Java Plug-In HTML Converter on the HTML page that invokes the applet to direct the applet ro run using the plug-in instead of the browser's default run time. </P><P CLASS="Body"><A NAME="pgfId-1087650"></A>Unzip the Java Plug-In HTML Converter download: </P><PRE CLASS="CODE"><A NAME="pgfId-1087651"></A>unzip htmlconv12.zip</PRE><P CLASS="Body"><A NAME="pgfId-1087653"></A>Add the <EM CLASS="CODE">HTMLConverter.java</EM> program or its directory to your <EM CLASS="CODE">CLASSPATH</EM>. <EM CLASS="A"></EM><A NAME="security"></A></P></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087654"></A>Security Policy File</H5><P CLASS="Body"><A NAME="pgfId-1087655"></A>In the Java 2 platform, applets are restricted to a sandbox-like environment and need permission to access system resources outside their restricted environment. Applets are restricted to resource access operations within their local directory. All other access operations require permission.</P><P CLASS="Body"><A NAME="pgfId-1087661"></A><EM CLASS="Bold">Types of Policy Files. </EM><A NAME="marker-1087656"></A><A NAME="marker-1087657"></A><A NAME="marker-1087658"></A><A NAME="marker-1087659"></A><A NAME="marker-1087660"></A>You need a policy file to grant access permissions to the <EM CLASS="CODE">Administration</EM> applet. If the applet runs on a disk other than the disk where the browser is running, the applet will also need to be signed. See Signed Applets (page 305) for information on signing and deploying applets. </P><P CLASS="Body"><A NAME="pgfId-1087662"></A>There are three kinds of policy files: system, user, and program. The system policy file is located in <EM CLASS="CODE">jdk1.2&#92;jre&#92;lib&#92;security&#92;java.policy</EM> or <EM CLASS="CODE">jre1.2&#92;lib&#92;security&#92;java.policy</EM> and contains permissions for everyone on the system. </P><P CLASS="Body"><A NAME="pgfId-1087663"></A>The user policy file is located in the user's home directory. The user policy file provides a way to give certain users additional permissions over those granted to everyone on the system. The permissions in the system file are combined with the permissions in the user file. </P><P CLASS="Body"><A NAME="pgfId-1087664"></A>A program policy file can be located anywhere. It is specifically named when an application is invoked with the <EM CLASS="CODE">java </EM>command or when an applet is invoked with applet viewer. </P><P CLASS="Body"><A NAME="pgfId-1087665"></A>When an application or applet is invoked with a specific policy file, the permissions in that policy file take the place of (are not combined with) permissions specified in the system or user policy file. Program policy files are used for program testing or intranet deployment of applets and applications. </P><P CLASS="Body"><A NAME="pgfId-1087667"></A><EM CLASS="Bold">Install the Security Policy File. </EM><A NAME="marker-1087666"></A>Place the security policy file in your home directory and make sure it is named <EM CLASS="CODE">java.policy</EM>. When the applet tries to perform an action that requires a policy file with a permission, the policy file is loaded from this directory and remains in effect until you exit and restart the browser. If an applet tries to perform an access operation without the right permission, it quietly quits without raising either an applet or browser error. </P><P CLASS="Body"><A NAME="pgfId-1087668"></A><EM CLASS="Bold">Change the Name or Location. </EM>You can change the name and/or location of the default system or user policy file. Edit the <EM CLASS="CODE">jdk1.2&#92;jre&#92;lib&#92;security&#92;java.security</EM> or <EM CLASS="CODE">jre1.2&#92;lib&#92;security&#92;java.security</EM> file and add a third entry specifying the name and location of an alternative policy file. </P><PRE CLASS="CODE"><A NAME="pgfId-1087669"></A>policy.url.1=file:${java.home}&#92;lib&#92;security&#92;java.policypolicy.url.2=file:${user.home}&#92;java.policypolicy.url.3=file:&#92;&lt;mypolicyfile path and name&gt;</PRE><UL><P CLASS="NOTE"><A NAME="pgfId-1087670"></A>NOTE On Windows/NT machines, you might place the policy file in the <EM CLASS="CODE">C:&#92;Winnt&#92;Profiles&#92;&lt;userid&gt;&#92;java.policy</EM> directory. </P></UL></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087671"></A>Run the <EM CLASS="B-code">Administration</EM> Applet</H5><P CLASS="Body"><A NAME="pgfId-1087672"></A>Copy the JAR file with the <EM CLASS="CODE">Administration</EM> applet and policy file to its final location. In this example, that location is the <EM CLASS="CODE">&#92;home&#92;zelda&#92;public_html</EM> directory. Next, extract the applet class file and policy file from the JAR file: </P><PRE CLASS="CODE"><A NAME="pgfId-1087673"></A>copy admin.jar &#92;home&#92;zelda&#92;public_html jar xf applet.jar</PRE><P CLASS="Body"><A NAME="pgfId-1087674"></A>The extraction places the policy file under <EM CLASS="CODE">public_html</EM> and creates an <EM CLASS="CODE">admin</EM> directory under the <EM CLASS="CODE">public_html</EM> directory with the applet class file in it. Rename the policy file in the <EM CLASS="CODE">public_html</EM> directory to <EM CLASS="CODE">java.policy</EM> and copy it to your home directory. </P><P CLASS="Body"><A NAME="pgfId-1087675"></A>In the <EM CLASS="CODE">public_html</EM> directory, create an HTML file that invokes the <EM CLASS="CODE">Administration</EM> applet class. Be sure to include the <EM CLASS="CODE">admin</EM> directory when you specify the applet class to the <EM CLASS="CODE">CODE</EM> option. Note that when using Java Plug-In, you cannot have the browser load the class file from the JAR file. </P><PRE CLASS="CODE"><A NAME="pgfId-1087676"></A>&lt;HTML&gt;&lt;BODY&gt;&lt;APPLET CODE=admin/AdminApplet.class  WIDTH=550  HEIGHT=150&gt;&lt;/APPLET&gt;&lt;/BODY&gt;&lt;/HTML&gt;</PRE><PRE CLASS="CODE"><A NAME="pgfId-1087677"></A><EM CLASS="Bold">Start the HTML Converter.  </EM>java HTMLConverter</PRE><P CLASS="Body"><A NAME="pgfId-1087678"></A>In the HTML Converter graphical user interface shown in Figure 9.3, select <EM CLASS="CODE">One File</EM>, specify the path to the <EM CLASS="CODE">admin.html</EM> file, and click the <EM CLASS="CODE">Convert</EM> button. After the conversion completes, load the <EM CLASS="CODE">admin.html</EM> file in your browser.</P><DIV><H6 CLASS="FC"><A NAME="pgfId-1087683"></A>Figure 9.3 <A NAME="40342"></A>HTML Converter user interface</H6><DIV><IMG SRC="CH09-3.gif"></DIV></DIV></DIV><DIV><H5 CLASS="B"><A NAME="pgfId-1087684"></A>How Does It Work?</H5><P CLASS="Body"><A NAME="pgfId-1087685"></A>On Windows machines, the Java Plug-In finds the JRE by running the OLE custom control file <EM CLASS="CODE">beans.ocx</EM> installed by default in the <EM CLASS="CODE">&#92;Program Files&#92;JavaSoft&#92;1.2&#92;bin</EM> Web browser directory. The OLE control examines the Windows registry to find the Java Plug-In key and uses the value associated with that key to find the installed JRE. </P><P CLASS="Body"><A NAME="pgfId-1087686"></A>If you find that the wrong JRE is being loaded, use <EM CLASS="CODE">regedit</EM> to check the Java Plug-In registry values for the current user. If no JRE is installed, the control checks the Java Plug-in values for <EM CLASS="CODE">HKEY_LOCAL_MACHINE</EM>. You should see a value for Java Runtime Environment under <EM CLASS="CODE">Software&#92;JavaSoft</EM>. </P><P CLASS="Body"><A NAME="pgfId-1026120"></A>&nbsp;</P></DIV></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?