how can I get the url?

A

Andrew Thompson

What exactly do you mean by 'get'?
Applet.getAppletContext().showDocument(URL) ?

This method will display a new web page (if your lucky),
but is not reliable, and I suspect not what you want..

To get an URL representing the document base, the
address of the web page itself, try..

java.applet.Applet.getDocumentBase()

...you might need to hack that a bit to get the exact information
you are after (e.g. do a String.lastIndexOf("/") to trim the tail end)

HTH

Andrew T.
 
S

Simon

Andrew said:
What exactly do you mean by 'get'?


This method will display a new web page (if your lucky),
but is not reliable, and I suspect not what you want..

You are probably right. I was not sure what the OP was asking for, hence the
question mark. Probably your answer is the right one. I thought he wanted to
display something because that was supposed to happen after a button was clicked.

Cheers,
Simon
 
T

Thomas Fritsch

Simon said:
Applet.getAppletContext().showDocument(URL) ?

In addition to what Simon and Andrew wrote:

You get the page, which contains the applet, by:
URL docBase = this.getDocumentBase();
// you'll get "http://localhost:14654/aes/cTrace/default.aspx"

You can construct new URLs from it by:
URL url = new URL(docBase, "bla.html");
// you'll get "http://localhost:14654/aes/cTrace/bla.html"
or
URL url = new URL(docBase, ".");
// you'll get "http://localhost:14654/aes/cTrace/"

Finally you can try to show this URL:
this.getAppletContext().showDocument(url);
 
A

Andrew Thompson

Thomas Fritsch wrote:
.....
URL docBase = this.getDocumentBase();
// you'll get "http://localhost:14654/aes/cTrace/default.aspx"

You can construct new URLs from it by:
URL url = new URL(docBase, "bla.html");
// you'll get "http://localhost:14654/aes/cTrace/bla.html"

Huhh!

I would not have known that if you had not mentioned it.
I would not have believed it unless I tried it and saw it work.
After revisiting the JavaDocs for that constructor again,
and having become confused by the text within the third
sentence, I *still* do not understand why it works.

It is funky though (and much better than rolling a custom
version using String.indexOf()!).

Andrew T.
 
T

Thomas

thanks, All
I hava solved my problem using the code blew:
URL codeBase = getCodeBase();
.......
about the mean of "get", I am sorry for my inattention.
I mean that: I want to get a new URL based by the URL of the Applet.
thanks!

Best Regards,
Thomas
 
T

Thomas Fritsch

Andrew said:
Thomas Fritsch wrote:
....



Huhh!

I would not have known that if you had not mentioned it.
I would not have believed it unless I tried it and saw it work.
Andrew, nice to dumbfound you ;-)
After revisiting the JavaDocs for that constructor again,
and having become confused by the text within the third
sentence, I *still* do not understand why it works.
Agreed. The JavaDoc of URL(URL,String) is next to incomprehensible
(caused kind of StackOverflowException in my head).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,085
Members
48,773
Latest member
Kaybee

Latest Threads

Top