|
Quick Lists
|
|
Bug ID:
|
4710854
|
|
Votes
|
2
|
|
Synopsis
|
JApplet.getCodeBase() and getDocumentBase() don't work as documented
|
|
Category
|
java_plugin:doc
|
|
Reported Against
|
1.4
, 1.4.1
, hopper
, 1.0-b68
|
|
Release Fixed
|
|
|
State
|
11-Closed, duplicate of 4456393,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
4456393
,
4712311
,
4816483
,
4712728
|
|
Submit Date
|
03-JUL-2002
|
|
Description
|
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
FULL OPERATING SYSTEM VERSION : Win2kPro, all updates
EXTRA RELEVANT SYSTEM CONFIGURATION :
Latest docs and JDK
A DESCRIPTION OF THE PROBLEM :
getDocumentBase() returns an URL to the html file in which
the applet is embeded, not the parent dir of the html file.
Docs read-
getDocumentBase
public URL getDocumentBase()
Returns an absolute URL naming the directory of the
document in which the 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/
Returns-
the URL of the document that contains this applet.
see getCodeBase() also.
*********************************************************
getCodeBase() returns the parent of the html file the applet
is embedded in, not the URL of the applet itself.
Docs read:
public URL getCodeBase()
Gets the base URL. This is the URL of the applet itself.
Returns:
the URL of this applet.
See getDocumentBase() also
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.) make and applet, Mine just had:
public void init()
{
docBase = this.getDocumentBase();
codeBase = this.getCodeBase();
}
public void paint(Graphics g)
{
g.drawString(docBase.toString(), 25, 50);
g.drawString(codeBase.toString(), 25, 100);
}
2.) Make an html file with an <applet tag>
3.) Request it.
EXPECTED VERSUS ACTUAL BEHAVIOR :
expect: url to directory html file is in
expect: the url of the applet itself
actual: url to the html file
actual: url to the directory of the html file
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package chapter4;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class JTMSplitPane extends JApplet
{
URL docBase;
URL codeBase;
public void init()
{
docBase = this.getDocumentBase();
codeBase = this.getCodeBase();
}
public void paint(Graphics g)
{
g.drawString(docBase.toString(), 25, 50);
g.drawString(codeBase.toString(), 25, 100);
}
}
***************************************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>chapter4.JTMSplitPane</title></head><body>
<Applet code=chapter4.JTMSplitPane width=400 height=300></Applet>
</body></html>
---------- END SOURCE ----------
(Review ID: 153868)
======================================================================
|
|
Work Around
|
N/A
|
|
Evaluation
|
The applet spec is owned by plugin, so I'll reassign to that subcategory.
xxxxx@xxxxx 2002-07-07
This is the evaluation I got from java.sun.com:
=============================================
public URL getDocumentBase()
Returns an absolute URL naming the directory of the document in
which the 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/
Returns:
the URL of the document that contains this applet.
==============================================
This description is copied directly from Applet.java file and sounds
VERY contradictory. First it explains that it should return an
"absolute URL naming the directory of the document in which the applet
is embedded". After that it gives an example that cuts off the
"index.html" part of the URL, and in conclusion it says that URL of the
document that contains this applet should be returned.
I looked through a bunch of books, and some documentation that
is available online, as well as documentbase standard for the HTML.
Conclusion: the very last line of the description is correct. This:
===============================
The document base is:
http://java.sun.com/products/jdk/1.2/
=================================
should not be mentioned at all.
*******************************************************************
For the description of getCodeBase() I have to say that it is neither
correct, nor complete.
This is what it says in documentation at java.sun.com:
==================================
public URL getCodeBase()
Gets the base URL. This is the URL of the applet itself.
Returns:
the URL of this applet.
===================================
While it should say that getCodeBase() returns the "codebase" parameter
of the applet tag.
Here is an example:
<html><head><title>chapter4.JTMSplitPane</title></head><body>
<Applet code=JTMSplitPane codebase="./source" width=600 height=300>
</Applet></body></html>
If this html is stored at
http://java.sun.com/products/plugin/demos/demo.html, then the codebase
should be http://java.sun.com/products/plugin/demos/source
If we have the following html page:
<html><head><title>chapter4.JTMSplitPane</title></head><body>
<Applet code=JTMSplitPane width=600 height=300>
</Applet></body></html>
As you see this page does not mention "codebase" parameter at all. In
this case getCodeBase should return the URL where the html document is
residing. So, in case if we have
http://java.sun.com/products/plugin/demos/demo.html, then codebase in
this case would be http://java.sun.com/products/plugin/demos/
*****************************************************
Documentation for Applet.java should be changed for both getCodeBase() and getDocumentBase(). Current documentation is incorrect and confusing. It needs to be updated as soon as possible.
If you have any questions, please feel free to contact me.
xxxxx@xxxxx 2002-07-15
This CR is fixed in most part by fixing 4456393.
xxxxx@xxxxx 2005-04-21 06:37:13 GMT
The documentation has been cleaned up as part of 4456393.
xxxxx@xxxxx 2005-07-14 02:57:33 GMT
Posted Date : 2005-07-14 02:57:33.0
|
|
Comments
|
Submitted On 05-MAY-2003
dfong63
i just ran into this bug myself, while trying to figure out
why some
example code i downloaded from the net didn't work.
as for what should be fixed:
here's for my opinion.
i agree that the documentation for both getCodeBase and
getDocumentBase is unclear, but i think the names of the
methods (-Base) suggest that they should both return
URL's for directories, rather than for the document or applet.
this functionality is consistent with the names, and provides
a useful service.
of course it makes no sense at all to have one return a
directory
and the other return a document.
Submitted On 30-JUL-2004
JamFlava
On JRE 1.42_03, getDocumentBase gives the URL of the server as opposed to the location where the applet-jar is living
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |