The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
When applets are deployed by using the Java Network Launch Protocol (JNLP), the Java Plug-in software launches the applet after downloading the JNLP file from the network. 使用Java网络启动协议(JNLP)部署小程序时,Java插件软件会在从网络下载JNLP文件后启动小程序。Beginning in the Java SE 7 release, you can reduce the time it takes for applets to launch, by embedding the JNLP file in the web page itself so that an additional network request can be avoided the first time the applet is loaded. 从JavaSE7版本开始,您可以通过将JNLP文件嵌入网页本身来减少小程序启动所需的时间,这样就可以在小程序第一次加载时避免额外的网络请求。This will result in applets launching quickly on the web browser.这将导致小程序在web浏览器上快速启动。
A Base64 encoded JNLP file can be embedded in the 在网页中部署小程序时,可以在jnlp_embedded
parameter when deploying an applet in a web page. jnlp_embedded
参数中嵌入Base64编码的JNLP文件。The attributes of the <jnlp>
element should meet the following restrictions:<jnlp>
元素的属性应满足以下限制:
href
attribute should contain a relative path.href
属性应该包含一个相对路径。codebase
attribute should not be specified. codebase
属性。The following steps describe how to embed a JNLP file in a web page to deploy an applet.以下步骤描述如何在网页中嵌入JNLP文件以部署小程序。
JNLP
file for your applet. JNLP
文件。<?xml version="1.0" encoding="UTF-8"?> <!-- href attribute contains relative path; codebase attribute not specified --> <jnlp href="dynamictree_applet.jnlp"> <information> <title>Dynamic Tree Demo</title> <vendor>Dynamic Team</vendor> </information> <resources> <!-- Application Resources --> <j2se version="1.7+" /> <jar href= "dist/applet_ComponentArch_DynamicTreeDemo/DynamicTreeDemo.jar" main="true" /> </resources> <applet-desc name="Dynamic Tree Demo Applet" main-class="appletComponentArch.DynamicTreeApplet" width="300" height="300"> </applet-desc> <update check="background"/> </jnlp>
base64
, uuencode
jnlp_embedded
parameter with it's value set to the Base64 encoded JNLP string. Make sure to include only the actual Base64 bytes without any encoding tool specific headers or footers. <script src="https://www.java.com/js/deployJava.js"></script> <script> var attributes = {} ; <!-- Base64 encoded string truncated below for readability --> var parameters = {jnlp_href: 'dynamictree_applet.jnlp', jnlp_embedded: 'PCEtLSANCi8qDQogKiBDb ... bmxwPg==' } ; deployJava.runApplet(attributes, parameters, '1.6'); </script>
Some encoding tools may wrap the encoded string into several 76-column lines. To use this multi-line attribute value in JavaScript code, specify the attribute value as a set of concatenated strings. You can include the multi-line attribute value as is if the applet is deployed directly with the <applet>
HTML tag.
Open
in a browser to view the Dynamic Tree Demo applet that is launched by using the JNLP file embedded in the web page.AppletPage.html
Download source code for the Embedded JNLP example to experiment further.