【问题标题】:Javascript absolute path to resource file and java class资源文件和java类的Javascript绝对路径
【发布时间】:2014-12-24 17:24:47
【问题描述】:

我正在关注 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 所在的同一文件夹,将路径更新为“Sample.mov”而没有“C:\”。它奏效了。在此之前我尝试了所有可能的组合( / 或 // 或 \ 或 file:///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 时钟工作。我也尝试了每种组合,但浏览器只是没有“看到”JavaClock 类?无论我是否从 IDE(Netbeans 直接通过从浏览器(IE、Firefox 或 Chrome)打开 HTMK 页面来调整它。浏览器抱怨 JavaClock.class 不存在?

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

文件位于此屏幕截图中:

【问题讨论】:

    标签: java javascript html file netbeans


    【解决方案1】:

    我刚刚发现错误在哪里(怪书的作者): 它应该是(对于 CODEBASE)class 而不是 classes

    应该是:

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

    而不是

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

    现在可以了(即使在本地机器上):

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-26
      • 2011-09-17
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多