Javascript资源文件和java类的绝对路径

时间:2014-12-24 17:24:48

标签: java javascript html file netbeans

我正在关注JavaScript的旧教程(来自书籍),我在使其工作时遇到了一些麻烦。操作系统是Windows 7/84,IDE是Netbeans 8.02。浏览器是IE 11,以及最新版本的Chrome和Firefox。

以下是代码:

<HTML>
    <HEAD><TITLE>Detecting embedded objects (applets, plug-ins, etc.)</TITLE>

        <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!-- Hide from browsers that do not support JavaScript
            function detectPlugins() {
                if (navigator.plugins.length > 0) {
                    var pluginDescription = "";

                    for (var numPlugins = 0; numPlugins < navigator.plugins.length; numPlugins++) {
                        pluginDescription = pluginDescription + " " + navigator.plugins[numPlugins].name
                    }

                    alert(navigator.plugins.length + " browser plug-ins detected: "
                            + pluginDescription);

                }
                else {
                    alert("No browser plug-ins detected. (Remember, IE doesn't support plug-ins.)")
                }

            }


            function detectApplets() {
                if (document.applets.length > 0) {
                    alert(document.applets.length + " Java applets detected. (Rememember, IE counts applets as embedded objects.)")

                }
                else {
                    alert("No Java applets detected.")
                }
            }

            function detectEmbeds() {

                if (navigator.appName == "Microsoft Internet Explorer") {
                    // The user is running IE, so check for objects
                    // embedded using the OBJECT tag.
                    //
                    // The readyState property of an object embedded
                    // using the OBJECT property can contain one of 3
                    // values:
                    // 0 = uninitialized
                    // 1 = loading
                    // 4 = finished loading and ready to go

                    if (document.QTsample.readyState == 4) {
                        alert("Detected the QTsample embedded object");
                    }

                    if (document.clock.readyState == 4) {
                        alert("Detected the clock embedded object");
                    }

                }
                else {
                    if (navigator.appName == "Netscape") {


                        if (document.embeds.length > 0) {
                            alert(document.embeds.length + " embedded object(s) detected.")


                        }
                        else {
                            alert("No embedded objects detected.");
                        }
                    }
                }
            }

            // --> Finish hiding
        </SCRIPT>

    </HEAD>
    <BODY>
        Two embedded objects appear below:
        <OL>
            <LI><b>A sample movie provided free by QuickTime (Sample.mov).</b>
                Note: IE identifies applets as objects. IE does not recognize browser plug-ins. (IE supports
                ActiveX objects instead of plug-ins.)
            <LI><b>A sample Java applet provided free by Sun Microsystems (JavaClock.class)</b>
                Note: Navigator identifies applets as applets.
        </OL>

        <!--
        You use the OBJECT tag to embed an ActiveX component into a page meant for MSIE;
        you use the EMBED tag to embed a plug-in into a page meant for Navigator.
        Notice the difference between the way the value of the SRC
        variable must be specified.
        // -->

        <OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320" HEIGHT="250"
                ID="QTsample" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">
            <PARAM name="SRC" VALUE="C:\Program Files (x86)\QuickTime\Sample.mov">
            <PARAM name="AUTOPLAY" VALUE="true">
            <PARAM name="CONTROLLER" VALUE="true">

            <EMBED SRC="file://C:\Program Files (x86)\QuickTime\Sample.mov" WIDTH="320" HEIGHT="250" 
                   AUTOPLAY="true" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/">
        </OBJECT>

        <!--
        This Java applet is freely available from Sun Microsystems.  For more info, visit http://java.sun.com/openstudio/applets/clock.html
        Note: the APPLET tag was deprecated in HTML 4.0, which means that programmers are encouraged to use the OBJECT tag
        (instead of the APPLET tag) to embed Java applets in Web pages. Future browsers may not support the APPLET tag.
        // -->

    <APPLET ID="clock" CODEBASE="classes" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">
        <PARAM  NAME="bgcolor"  VALUE="FFFFFF">
        <PARAM  NAME="border"   VALUE="5">
        <PARAM  NAME="ccolor"   VALUE="dddddd">
        <PARAM  NAME="cfont"    VALUE="TimesRoman|BOLD|18">
        <PARAM  NAME="delay"    VALUE="100">
        <PARAM  NAME="hhcolor"  VALUE="0000FF">
        <PARAM  NAME="link"     VALUE="http://java.sun.com/">
        <PARAM  NAME="mhcolor"  VALUE="00FF00">
        <PARAM  NAME="ncolor"   VALUE="000000">
        <PARAM  NAME="nradius"  VALUE="80">
        <PARAM  NAME="shcolor"  VALUE="FF0000">
    </APPLET>
    <P>
    <FORM>
        <INPUT TYPE="button" VALUE="detect embedded objects" onClick="detectEmbeds()">
        <INPUT TYPE="button" VALUE="detect plug-ins" onClick="detectPlugins()">
        <INPUT TYPE="button" VALUE="detect applets" onClick="detectApplets()">
    </FORM>
</BODY>
</HTML>

最初的书籍路径如下:

<PARAM name="SRC" VALUE="c:\Program Files\QuickTime\Sample.mov">

<EMBED SRC="file://c:\Program Files\QuickTime\Sample.mov" WIDTH="320"
HEIGHT="250" AUTOPLAY="true" CONTROLLER="true"
PLUGINSPAGE="http://www.apple.com/quicktime/download/">

所以我改变了它以反映Windows 7 64位程序路径。 它没有用。然后我将Sample.mov移动到C:\ Sample.mov并在代码中更新了路径,但那也没有用?然后我将Sample.mov移动到同一个文件夹,其中是html,更新的路径只是&#34; Sample.mov&#34;没有&#34; C:\&#34;。它奏效了。我之前尝试了所有可能的组合(/或//或\或文件:/// C:/ ...等)。但它只是没有任何路径。

因此,为了在IE和Firefox中打开QuickTime视频,我最终得到了这个:

<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="320" HEIGHT="250"
        ID="QTsample" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">
    <PARAM name="SRC" VALUE="Sample.mov">
    <PARAM name="AUTOPLAY" VALUE="true">
    <PARAM name="CONTROLLER" VALUE="true">

    <EMBED SRC="Sample.mov" WIDTH="320" HEIGHT="250" 
           AUTOPLAY="true" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/">
</OBJECT>

问题1:我应该如何使用位于文档根目录之外的文件,就像在真实示例中所假设的那样。

不幸的是,我不能让java时钟工作。我也尝试了所有组合,但浏览器只是没有&#34;看到&#34; JavaClock类?无论我是从IDE(通过从浏览器(IE,Firefox或Chrome)打开HTMK页面直接使用Netbeans)。浏览器抱怨JavaClock.class不存在?

问题2:我应该如何使JavaClock类也能正常工作?

文件位于此屏幕截图中: enter image description here

1 个答案:

答案 0 :(得分:0)

我刚刚发现错误的地方(责怪本书的作者): 它应该是(对于CODEBASE)而不是

应该是:

<APPLET ID="clock" CODEBASE="class" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">

而不是

<APPLET ID="clock" CODEBASE="classes" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">

现在没问题(即使在本地机器上):

enter image description here