简体   繁体   中英

How does the Java getCodeBase() method work?

So I learned about the getCodeBase() method today in my programming class and to be honest, I'm really interested in it and how it works in general. All I know is that it finds the directory of where the source code is stored and it is mostly used in applets. But anyone explaining, in detail, how it actually works like the technicalities and such, I would be super grateful! By the way, I started Java 6 months ago. Thanks!

This is what I learned, just to put a little code in here.

cards[0] = getImage( getCodeBase(), "cards_gif/1.gif" );

getCodeBase() in this case, is used to initalize a part of an array to a image.

它返回HTML中指定的代码库或其默认值。

getDocumentBase()

Gets the URL of the document in which this applet is embedded .

For example, suppose an applet is contained within the document:

http://java.sun.com/products/jdk/1.2/index.html

The document base is:

http://java.sun.com/products/jdk/1.2/index.html

getCodeBase()

Gets the base URL . This is the URL of the directory which contains this applet.


I want to delete this post, but can't do it as it's accepted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM