Solved

Javascript absolute path to resource file and java class

Posted on 2014-12-24
12
305 Views
Last Modified: 2014-12-29
I am following and old tutorial (from book) for JavaScript and I have some troubles with making it work. OS is Windows 7/84 and IDE is Netbeans 8.02. Browsers are IE 11, and latest versions of Chrome and Firefox.

Here is the code:

<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>

Open in new window


Originally in book paths were like:
<PARAM name="SRC" VALUE="c:\Program Files\QuickTime\Sample.mov">

Open in new window

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

Open in new window

So I changed that to reflect Windows 7 64 bit program path. It didn't work. Then I moved Sample.mov to C:\Sample.mov and updated paths in code as well, but that didn't work either? Then I moved Sample.mov to same folder where is html, updated paths just to "Sample.mov" without "C:\". And it worked. I tried all possible combinations prior to that ( / or // or \ or file:///C:/... etc). But it works only without any path.

So in order to make QuickTime video opening in both IE and Firefox I ended up with this:
<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>

Open in new window

QUESTION 1 IS: how should I make it work with file located outside of document root, like it was supposed in genuine example.

Unfortunately, I can't make java clock work. I also tried every combination but browser just don't "see" JavaClock class? No matter if I tun it from IDE (Netbeans of directly by opening HTMK page from browser (IE, Firefox or Chrome). Browsers are complaining that JavaClock.class doesn't exist?

QUESTION 2 IS: how should I make that JavaClock class work as well?.

Files are located as on this screenshot:
Files location in Netbeans IDEFiles location in Netbeans IDE
0
Comment
Question by:KPax
  • 6
  • 5
12 Comments
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 40517089
You need a new tutorial.  Local absolute paths are not supported in modern browsers.  And most won't open a 'file://' resource from an 'http://' resource.  It's considered a security breach.

And JAVA has had too many security problems in the last year.  These days, even when it is installed properly, you have to go into the Java Console and enable it's use in your web browsers.  The default state is 'disabled'.
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
ID: 40517092
The src values should be the path relative to the site or localhost, you are doing absolute paths on the client which is not allowed (unless you were running the file directly in the browser locally using your own file system)
So the path should be more like you have it removing all paths and just having the movie in the same folder. If in the same directory you had another folder called movies and the .mov file was in that then you path would become

movies/Sample.mov
0
 

Author Comment

by:KPax
ID: 40517110
OK, I understand, I can run QT movie on local machine and it works OK on the web as well, but I can't make that JavaClock class work, browser says it can't find it.
I uploaded all of it here.
How should I make that path for Java class, right now it is:

 <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>

Open in new window

0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40517124
Here is what I get in Firefox from your page.
EMBEDed ObjectsI would have to install a plugin to run your JAVA.  Although I don't know if it would run even then since I have not enabled JAVA in my browsers.
0
 

Author Comment

by:KPax
ID: 40517128
Here is what it looks like when you have QuickTime plugin and Java plugin installed:
Screenshot from browser
Clicking on details reveals no useful info, just:

Java Plug-in 10.71.2.14
Using JRE version 1.7.0_71-b14 Java HotSpot(TM) Client VM
User home directory = C:\Users\Nenad
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40517136
I actually do have them installed but the Default in Firefox is to make you enable them when they are requested by a page.  In addition, as I stated above,  JAVA won't run unless you specifically enable it in the JAVA console which is normally found in the Control Panel.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:KPax
ID: 40517142
Yes, I know that about JAVA, I am JAVA developer, and even had lots of HTML/CSS/JavaScript programming years and years ago. Meanwhile I was developing JAVA EE and Android apps, and now I want to recall making websites with HTML/CSS/JavaScript/Ajax, so I took my old book from stack and doing all of the tutorials again.  I know how to set web browser and not only that but also how to setup Weblogic or JBoss, or Tomcat or Apache servers (LAMP). So problem is not about JAVA or browser or enabling plugins but simply I can't figure out right now how to handle absolute or relative path in JavaScript.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40517151
Javascript (or anything else) in modern browsers is not normally allowed to use absolute paths and in most situations, not allowed to access 'local' paths at all.  Javascript can load image files from the server but normally only from the web root, not above it, and AJAX can do the same.

HTML/CSS/JavaScript programming years and years ago is Not what it is now in terms of file access and restrictions.  Take a look at the View Source of a lot of working pages and you will not see any absolute paths.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40517153
You might want to look at this page on Browser Security:  https://code.google.com/p/browsersec/wiki/Part2
0
 

Accepted Solution

by:
KPax earned 0 total points
ID: 40517157
No, I just found where the error is (blame to author of the book):
It should be (for CODEBASE) class not classes

It should be:
<APPLET ID="clock" CODEBASE="class" CODE="JavaClock.class" WIDTH="150" HEIGHT="150">

Open in new window


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

Open in new window


Now it is ok (even on local machine):

C:\Users\Nenad\Pictures\My Screen Shots\Screen Shot 12-24-14 at 11.50 PM.PNG
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40517187
Glad you got it figured out.
0
 

Author Closing Comment

by:KPax
ID: 40521508
Trivial error, the worst kind of errors, so much annoying but so easily to be overlooked.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now