Use the applet tag on a webpage

Source: Internet
Author: User
Tags comment tag

Although applet is not recommended for W3C, It is a recommended practice to deploy Applet in the enterprise intranet (Intranet). We will first discuss the use of the <APPLET> label.

<APPLET> usage

In the early stages of Applet deployment, using the <APPLET> tag is a very common practice. You can find the list of all attributes of the applet tag here, http://www.w3schools.com/tags/tag_applet.asp, in detail.

1. The following is an example of using Applet:

<APPLET code = applet1.class width = "200" Height = "200">

Your browser does not support the <code> applet </code> tag.

</APPLET>

Generally, we mainly use these attributes:

The Code attribute refers to the Applet Class, that is, inheriting the subclass from the java. Applet. applet or Java. Swing. japplet class. This attribute value must store the Applet Class path for you;

The width attribute refers to the width that your applet occupies in the browser.

The height attribute indicates the height your applet occupies in the browser.

2. We usually use these attributes, but sometimes we package the applet into a jar file, then we need to use the archive attribute, for example:

<APPLET code = package. applet1.class archive = "app. Jar" width = "200" Height = "200">

Your browser does not support the <code> applet </code> tag.

</APPLET>

This instance means that the app is in the file where you store HTML files. find the package in the jar file. applet1.class: the Applet Class. If you want to use multiple jar files, separate the jar files with English-encoded commas (,) in the archive attribute values.

3. Sometimes the file we want to load is no longer in the current directory, but in its subdirectory or parent directory, we can use the codebase attribute, for example:

<APPLET code = applet1.class codebase = "app" width = "200" Height = "200">

Your browser does not support the <code> applet </code> tag.

</APPLET>

In this way, Java Plug-in will be searched in the app subdirectory under the current directory, and the applet1.class class will be loaded.

4. We can also pass parameters to the Applet Class, for example:

<APPLET code = applet1.class codebase = "app" width = "200" Height = "200">

<Param name = "param1" value = "1"/>

<Param name = "param2" value = "2"/>

Your browser does not support the <code> applet </code> tag.

</APPLET>

In this way, we can get these parameters in the applet we write through the getparameter (string PARAM) method, so that we can configure the program in the applet tag, the input parameter name is the name attribute value of the param label.

 

<Object> Use

The object tag is usually used only in Internet Explorer. For example:

<Object
Classid = "CLSID: 8ad9c840-044e-11d1-b3e9-00805f499d93"
Width = "200" Height = "200"
Codebase = "http://java.sun.com/products/plugin/autodl/
Jinstall-1_5_0-windows-i586.cab # version =, ">
<Param name = "code" value = "applet1.class">
</Object>

Attribute introduction:

1. The classid attribute indicates the minimum Java Plug-in version to be used. This indicates that the currently installed Java Plug-in version must be later than the classid, otherwise the applet cannot run. Generally, the classid attribute values used in Internet Explorer are fixed, namely:

Classid = "CLSID: 8ad9c840-044e-11d1-b3e9-00805f499d93"

This format indicates that the latest JRE version in IE is used.

Classid also has another format, as shown below:

Classid = "CLSID: cafeefac-XXXX-yyyy-zzzz-abcdeffedcba"

XXXX-yyyy-zzzz is the Java Plug-in version. For example, version 1.6.0 can be expressed:

Classid = "CLSID: CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA"

2. The property of width and height is the same as that of applet.

3. codebase is an optional attribute and has the following functions:

The version of JRE (Java Runtime Environment) installed on the local machine is earlier than the version specified by the classid attribute, and the browser downloads and installs JRE in this URL.

Codebase has the following format:

Codebase = <URL>

In this format, if the locally installed JRE version is not the version specified by classid, go to the specified URL for download and installation.

Codebase = <URL> # version = major, minor, micro, undate

In this format, if the JRE version installed on the local machine is smaller than the one specified in classid, download JRE from the specified URL.

Note: Separate them with commas.

Here we use sun to download the files (in. Cab format) for various versions of the installation files on the Windows platform, http://java.sun.com/javase/6/webnotes/install/jre/autodownload.html.

<Embed> label

Embed labels are usually used in Mozilla browsers, as follows:

<Embed code = "applet1.class"
Width = "200" Height = "200"
Type = "application/X-Java-applet; version = 1.6"
Pluginspage = "http://java.sun.com/javase/downloads/ea.jsp"/>

Attribute introduction:

1. The attributes of code, width, and height are the same in the applet tag.

2. the type property has the following format:

Type = "application/X-Java-applet; version = 1.6"
This format indicates that the MIME type is application/X-Java-Applet and the version is 1.6 or higher. If the locally installed JRE is larger than or equal to the value specified in the version, call this JRE. Otherwise, it points to the URL specified by the pluginspage attribute.

Type = "application/X-Java-applet; jpi-version = 1.5.0 _ 07

This format indicates that the locally running JRE version must be later than or equal to 1.5.0 _ 07. Otherwise, it points to the URL of pluginspage.

<JSP: plugin/> label usage

<JSP: plugin type = applet code = "molecule" codebase = "/html">
<JSP: Params>
<JSP: Param name = "molecule" value = "molecules/benzene. mol"/>
</Jsp: Params>
<JSP: fallback>
<P> unable to start plug-in. </P>
</Jsp: fallback>
</Jsp: plugin>

<JSP: plugin> is the root tag of the applet. All the actions performed by the applet on the JSP page are carried out here.

<JSP: param> is the same as <param> In the applet tag.

<JSP: Params> used to Package Multiple <JSP: param> labels

<JSP: fallback> used for Java Plug-in startup failure. if the content is executed smoothly, it will be ignored.

 

 

Other technical help

How can an applet run in different browsers?

Are there three solutions?

1. Use the applet tag

Applet labels are supported by most mainstream browsers.

2. Use HTML tags

<Object
Classid = "CLSID: CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA"
<Param name = "code" value = "applet1.class">
<Comment>
<Embed code = "applet1.class"
Type = "application/X-Java-applet; jpi-version = 1.6">
<Noembed>
No Java support.
</Noembed>
</Embed>
</Comment>
</Object>

In IE, ie recognizes the object tag and ignores the comment tag.

In the Mozilla browser, Mozilla ignores the object and classid to recognize comment labels.

3. Use Javascript
<HTML>
<Script language = "JavaScript">
VaR _ APP = navigator. appname;
If (_ APP = 'mozilla '){
Document. Write ('<embed code = "applet1.class "',
& Apos; width = "200" & apos "',
'Height = "200 "',
'Type = "application/X-Java-applet; version = 1.6"> ');
}
Else if (_ APP = 'Microsoft Internet Explorer '){
Document. Write ('<object ',
'Classid = "CLSID: 8ad9c840-044e-11d1-b3e9-00805f499d93 "',
& Apos; width = "200" & apos "',
& Apos; Height = "200" & gt ',
'<Param name = "code" value = "applet1.class"> ',
'</Object> ');
}
Else {
Document. Write ('<p> sorry, unsupported browser. </P> ');
}
</SCRIPT>
</Html>

Make sure that your browser's javascript interpreter is opened. In JavaScript, we can use the appname variable name to get the browser name. If

For Mozilla, JavaScript is used to write mozilla-related HTML code. For Microsoft Internet Explorer, HTML code related to IE is written.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.