Forum Stats

  • 3,836,888 Users
  • 2,262,203 Discussions
  • 7,900,133 Comments

Discussions

need help with passing URL of document into Applet

797160
797160 Member Posts: 75
edited Feb 15, 2011 8:52AM in New To Java
I have an applet, which is called by the file
file:///home/lyle/Desktop/linkit/hello.html

I am trying to access the URL of this file in my applet. So I tried the line
String completeURL = getDocumentBase().toString();

However, it is not returning the correct value - it returns the path, but not the filename (ie, not the whole URL)

To debug it, I added this line:
answers.append("url = " + completeURL + "\n");

Which returned the value
url = file:/home/lyle/Desktop/linkit/

Can anyone tell me why this is not returning the entire line?
Thanks!

Edited by: lkb3 on Feb 14, 2011 9:40 PM - fixed a typo
Tagged:

Answers

  • 793415
    793415 Member Posts: 7,279 Bronze Badge
    edited Feb 15, 2011 1:48AM
    lkb3 wrote:
    ..Can anyone tell me why this is not returning the entire line?
    That is not the behavior I see here. An SSCCE (http://pscode.org/sscce.html) based on your snippet*.
    // <applet code='WhereAmIApplet' width='500' height='100'></applet>
    import javax.swing.*;
    
    public class WhereAmIApplet extends JApplet {
    
        public void init() {
            String completeURL = getDocumentBase().toString();
            add( new JTextArea(
                completeURL +
                "\n" +
                System.getProperty("java.vm.version")) );
        }
    }
    Output from 3 runs.
    From TextPad launching as an applet
    file:/D:/projects/numbered/all/158WhereAmIApplet/tp028b26.html
    1.6.0-b105
    From TextPad launching the source in applet viewer
    file:/D:/projects/numbered/all/158WhereAmIApplet/WhereAmIApplet.java
    1.6.0-b105
    From FF, using an applet.html
    file:/D:/projects/numbered/all/158WhereAmIApplet/applet.html
    19.0-b09
    * BTW:
    1) When posting code, code snippets, XML/HTML or input/output, please use the code tags as described on the 'sticky post' at the top of the forum thread listing - those posts are there for a reason.
    2) For better help sooner, post an SSCCE. I might not have had the motivation to write what you had not bothered to add.

    Edit 3) Applets are not easy to develop/debug. Someone who is 'New to Java' should probably not be attempting applet development.

    Edited by: Andrew Thompson on Feb 15, 2011 5:47 PM
    793415
  • 797160
    797160 Member Posts: 75
    edited Feb 15, 2011 8:24AM
    Andrew,
    Thanks for the input on SSCCEs - I'll be sure to do that from now on.

    Anyway, the odd thing is that the behavior I described last night was compiled on my Ubuntu (Lucid Lynx) machine at home. When I recompile it here at work, using 1.4.2 on a Win XP machine, that line does return the whole URL. I dont know why it returned the results it did at home; perhaps the issue is Firefox on Linux...
    Regardless, all of my users (my app will reside on a corporate intranet) will be on Windows, so I'll see if I can replicate the error here at work...

    Edited by: lkb3 on Feb 15, 2011 5:24 AM
  • 793415
    793415 Member Posts: 7,279 Bronze Badge
    lkb3 wrote:
    ..Anyway, the odd thing is that the behavior I described last night was compiled on my Ubuntu (Lucid Lynx) machine at home. When I recompile it here at work, using 1.4.2 on a Win XP machine, that line does return the whole URL.
    I am guessing the it is not the compiler that matters, but the run-time. Are you using Sun's Java on Ubuntu or that other alternative that everyone recommends against?
This discussion has been closed.