Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 21 of 21

Thread: Uploading a Java Applet embedded in HTML to a Web server

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Uploading a Java Applet embedded in HTML to a Web server

    I have been having some trouble uploading my Java Applet embedded in HTML on to my Web server.
    The trouble is that when the Applet is on the server it does not run (HTML page is blank).
    However it works 100% when running it on my local computer.

    I suspect it has something to do with the packages and the relative path that the .class and .jar files are created in.

    Here is my code
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <P>
    <APPLET codebase="classes" code="com/mxgraph/examples/swing/EditorDriver.class"
            archive ="com/mxgraph/examples/swing/jgraphx.jar" width=850 height=635></APPLET>
    </P>
    </BODY>
    </HTML>

    How do i overcome this problem?


  2. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Currently the HTML file is in a separate parent folder (called "build").
    The .class and the imported .jar file referenced in the HTML file are in a different subfolder
    e.g. build>classes>com>mxgraph>examples>swing>EditorDri ver.class

    1) Do i need to include the URL of the website in the "code = .. " & "archive = ..." path

    2) Should i remove the package structure of the program so that all the classes are in the same folder with .jar and the HTML file?
    Thus removing the pathing problem

    3) does it matter that the path uses forward or back slashes
    ("com/mxgraph/examples/swing/EditorDriver.class" or "com\mxgraph\examples\swing\EditorDriver.class ")

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Do you get an error?

    You should check the hosts file.. make sure the applet allows connections.
    If the applet is a server for example.. the applet could be limited and set to localhost connections only. If it works on your local machine its because its "localhost" but if running it from a server website for example.. you would have to use the domain name / IP instead of the localhost itself.. so for example your website is Something. and the IP is 203.222.121.32 you would set it to host: 203.222.121.32

    But without knowing more information such as what type of applet is it.. and the exact problem, Etc is it showing you an error message on load?
    what web server are you using etc...

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Are the relative locations of the files on the server the same as they are on your PC?

    Are there any errors in the browser's java console?

    The code= attribute should be the name of the class, not a path.
    Why have the jar file nested so far away from the html file? Can they be in the same folder?

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Quote Originally Posted by macko View Post
    Do you get an error?

    You should check the hosts file.. make sure the applet allows connections.
    If the applet is a server for example.. the applet could be limited and set to localhost connections only. If it works on your local machine its because its "localhost" but if running it from a server website for example.. you would have to use the domain name / IP instead of the localhost itself.. so for example your website is Something. and the IP is 203.222.121.32 you would set it to host: 203.222.121.32

    But without knowing more information such as what type of applet is it.. and the exact problem, Etc is it showing you an error message on load?
    what web server are you using etc...
    Its quite a simple GUI program that extends JApplet.
    There is no network programming involved.
    When run on the website there is no error at all.
    The HTML starts by loading java and then turns blank and freezes.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Are the relative locations of the files on the server the same as they are on your PC?

    Are there any errors in the browser's java console?

  7. #7
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Quote Originally Posted by Norm View Post
    Are the relative locations of the files on the server the same as they are on your PC?

    Are there any errors in the browser's java console?

    The code= attribute should be the name of the class, not a path.
    Why have the jar file nested so far away from the html file? Can they be in the same folder?
    The build folder contains all the files (.class, . jar, .html) need for the java applet, and is placed in a directory called
    "http://www.cyberdesign.com.au/onlinehockeyplays/build/EditorDriver.html"

    There are no errors that pop up, the applet loads and freezes (you are welcomed to try the link and check it out).
    The "code=" attribute contains the name of the drier class within the path, because the classes are created in a package

    the .jar file does not need to be far away for the HTML file, but has to be within the 'codebase = classes' folder (build > classes ....)
    So it cant be in the same folder.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    placed in a directory called
    "http://www.cyberdesign.com.au/onlinehockeyplays/build/EditorDriver.html"
    That is the path to a file not a directory.
    code=" attribute contains the name of the drier class within the path, because the classes are created in a package
    Does the browser work ok with the slashes in the class name? I have always used .s

    it cant be in the same folder.
    For simple cases I always put the html file and the jar file in the same folder.


    Have you found the browser's java console yet?
    Here is what I get in my browser's java console:

    Java Plug-in 1.6.0_29
    Using JRE version 1.6.0_29-b11 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Norm
     
    ----------------------------------------------------
    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>
    ----------------------------------------------------
     
    Exception in thread "thread applet-com/mxgraph/examples/swing/EditorDriver.class-1" java.lang.ExceptionInInitializerError
    	at com.mxgraph.examples.swing.EditorDriver.init(EditorDriver.java:22)
    	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.util.MissingResourceException: Can't find bundle for base name com/mxgraph/examples/swing/resources/editor, locale en_US
    	at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
    	at java.util.ResourceBundle.getBundleImpl(Unknown Source)
    	at java.util.ResourceBundle.getBundle(Unknown Source)
    	at com.mxgraph.util.mxResources.add(Unknown Source)
    	at com.mxgraph.examples.swing.editor.BasicGraphEditor.<clinit>(BasicGraphEditor.java:73)
    	... 3 more

  9. #9
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    the browser works fine with both forward and back slashes in the class name when running the html file on my local computer.
    how do you use the ".s"? could you give an example

    How do you ge the browser's java console on mozilla firefox? is it an addon download?

    According to the error message you posted, it is not because of the bad path?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    code=com.mxgraph.examples
    just like you use in a package statement or import statement.

    How do you get the browser's java console
    Not sure where but its one of the browser's menu options.
    Also go to the Control Panel and find the Java icon. Somewhere in its setting you can turn on the java console.

  11. #11
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    I got the browser's java console and i get this error

    Exception in thread "thread applet-com/mxgraph/examples/swing/EditorDriver.class-10" java.lang.NoClassDefFoundError: Could not initialize class com.mxgraph.examples.swing.GraphEditor
    	at com.mxgraph.examples.swing.EditorDriver.init(EditorDriver.java:22)
    	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)

    this is what is my EditorDriver.class looks like
    package com.mxgraph.examples.swing;
    import javax.swing.JApplet;
    public class EditorDriver extends JApplet
    {
        private final int WIDTH = 850, HEIGHT = 635;
        public void init()
        {
            GraphEditor application = new GraphEditor();
            getContentPane().add (application);
            setSize (WIDTH, HEIGHT);
        }
    }

    I'm not very good at understanding error messages clearly.
    does the error mean that it can find my 'EditorDriver.class' but not my find my 'GraphEditor.class'?
    Both files are in the same directory though.
    what do i change to overcome this problem?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    I don't know why you got a different error message than I did.
    It looks like the code in the init method failed at line 22 trying to create the GraphEditor object.

    Is that all the text of the error message?

  13. #13
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Ya thats all i got from my java console
    how come it failed to create a GraphEditor object though? ><
    it works fine on my computer T_T

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    I guess something is wrong someplace.

  15. #15
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    it is because of the code:

    Document doc = mxUtils.loadDocument(GraphEditor.class.getResource(
                "/com/mxgraph/examples/swing/resources/default-style.xml")
                .toString());

    Which is inside my GraphEditor.class.
    The folder that contains that XML file is in the folder yet the program can't find it when uploaded to the web server.
    Is there anyway to resolve this?

    I'm guessing it also wont be able to find the images i use in the program as well:

    shapesPalette.addTemplate("Marker Yellow",
                new ImageIcon(GraphEditor.class
                .getResource("/com/mxgraph/examples/swing/images/marker_yellow.png")),
                "roundImage;image=/com/mxgraph/examples/swing/images/marker_yellow.png",
                20, 20,  "Marker Yellow");

    T_T

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    the program can't find it
    The getResource methods are the way to get "files" that are in a jar file.
    Try moving moving the getResouce calls out of the method call and print out the value returned.
    Try a different path by removing the leading / on the path.
    If you put the html file and jar file in test folders without any access to the files on your local disk,what happens when you load the html file into a browser?

  17. #17
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    The getRescource method do not get files that are in the jgraphx.jar file.
    The method gets files from the folders.
    The jgraphx.jar file is an imported library that i use for my program.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    You should put all the rest of your files into another jar file instead of having them as separate files on the server. The archive= attribute can have a list of jar files.

  19. The Following User Says Thank You to Norm For This Useful Post:

    wizdom (November 30th, 2011)

  20. #19
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    Ya that's a good idea. i was thinking about doing that, but I'm not sure how to do it :S
    I've been using Netbeans IDE and i have noticed that it creates a Jar file for you automatically, but not properly.
    I'll have to look up how to do it.

    BTW thank you VERY much for all your assistance.
    You have been very helpful.

  21. #20
    Junior Member
    Join Date
    Nov 2011
    Posts
    12
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    I managed to upload my JApplet to the website by creating a jar file ,
    <HTML>
    <HEAD>
     
    </HEAD>
    <BODY>
    <P>
    <APPLET code ="com.mxgraph.examples.swing.EditorDriver"
        archive="HockeyField.jar, jgraphx.jar"width=850 height=635></APPLET>
    </P>
     
    </BODY>
    </HTML>
    however now i get a few errors when using particular functions of the applet.
    like when i try to save, and mouse event
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)

    Here is the link to my applet again
    http://www.cyberdesign.com.au/online...torDriver.html

  22. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Uploading a Java Applet embedded in HTML to a Web server

    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    Unsigned Applets are not allowed to read most things from or write anything to a user's PC. You need to give it permission to read Property values like user.dir for example.

Similar Threads

  1. Replies: 2
    Last Post: October 27th, 2011, 08:51 AM
  2. Replies: 5
    Last Post: October 21st, 2011, 08:48 AM
  3. problem with uploading an image to server
    By jzarapsa in forum Java Servlet
    Replies: 3
    Last Post: October 17th, 2011, 09:29 PM
  4. HTML in Swing Components in Cached Applet
    By KevinWorkman in forum Java Applets
    Replies: 6
    Last Post: August 1st, 2011, 07:46 AM
  5. How would you use HTML to embed a Java applet within it?
    By javapenguin in forum Java Theory & Questions
    Replies: 1
    Last Post: May 5th, 2011, 05:16 AM

Tags for this Thread