Cannot load image in applet after placing it in a package  
Author Message
Gerrit Hulleman





PostPosted: 2004-6-30 17:32:00 Top

java-programmer, Cannot load image in applet after placing it in a package This has been a much discussed topic in several newsgroups, but I still
cannot figure it out.

I got this class: htmledit.class. Normal website linking to this class as an
applet. Several image files (gif&bmp) for toolbar images.

/
| -htmledit.class
|
|-image1.gif
\-image2.gif

Applet loads, no problem. images are used in the toolbar. Applet tag calls
"htmledit.class"

Trying to get the class in a package (due to OO reasons and java 1.4 jdk) I
get:
/
|-/main
| \-htmledit.class
|
|-image1.gif
\-image2.gif

Changed the header of the htmledit.class to main package, changed the html
code to call the class "main.htmledit.class". Applet loads, get null values
from getResource() call. No images are loaded.

This applet is not (yet) part of a jar file. Tried copying the image files
to the main directory, add codebase, place them in a jar with archieve
attribute in the applet tag, calling image file with a "/" in front of it.

Why is the main applet class no longer able to access the image files when
placed in a package?


G


 
Andrew Thompson





PostPosted: 2004-6-30 18:19:00 Top

java-programmer >> Cannot load image in applet after placing it in a package On Wed, 30 Jun 2004 11:31:51 +0200, Gerrit Hulleman wrote:

> This has been a much discussed topic in several newsgroups, but I still
> cannot figure it out.

Can you figure it out in an aplication?

Do that first.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Gerrit Hulleman





PostPosted: 2004-6-30 19:04:00 Top

java-programmer >> Cannot load image in applet after placing it in a package Had tried an app. That works The strange thing is that the problem only
occures when trying to load the applet using a webserver.

A java application is able to get the image using the '/' prefix. The sun
applet viewer is able to load the images using the same prefix. Using a
browser to the htm file
(file://localhost/D:/System/eclipse/workspace/htmledit2_test/Htmledit.htm),
images are loaded. (IE & Opera).

But when the browser loads the applet via the IIS server
(http://localhost/Htmledit.htm) (set to the same dir as the direct link),
images are left out.

This only happens if the Htmledit class is in a package. Otherwise images
are loaded. That is why I think about applet security. But I cannot get my
finger on it. Any suggestions?


"Andrew Thompson" <email***@***.com> wrote in message
news:17cfr5lkjz6m4$.3naf2umsfgl9$email***@***.com...
> On Wed, 30 Jun 2004 11:31:51 +0200, Gerrit Hulleman wrote:
>
> > This has been a much discussed topic in several newsgroups, but I still
> > cannot figure it out.
>
> Can you figure it out in an aplication?
>
> Do that first.
>
> --
> Andrew Thompson
> http://www.PhySci.org/ Open-source software suite
> http://www.PhySci.org/codes/ Web & IT Help
> http://www.1point1C.org/ Science & Technology


 
 
Andrew Thompson





PostPosted: 2004-6-30 19:19:00 Top

java-programmer >> Cannot load image in applet after placing it in a package On Wed, 30 Jun 2004 13:03:45 +0200, Gerrit Hulleman wrote:
> Any suggestions?

Do not top-post, is one.
<http://www.physci.org/codes/javafaq.jsp#netiquette>

> "Andrew Thompson" <email***@***.com> wrote in message
> news:17cfr5lkjz6m4$.3naf2umsfgl9$email***@***.com...
>> On Wed, 30 Jun 2004 11:31:51 +0200, Gerrit Hulleman wrote:
>>
>>> This has been a much discussed topic in several newsgroups, but I still
>>> cannot figure it out.
>>
>> Can you figure it out in an aplication?
..
> Had tried an app. That works The strange thing is that the problem only
> occures when trying to load the applet using a webserver.

What web-server? Put the applet up and
give us the URL..

This might be fixed by 'jar'ing your
package, but I cannot see how that will
help if the image is external, but I
am sure you can find resources in this
situation..

What is the 'codebase' attribute.. no,
stuff that, give us the URL.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
 
Gerrit Hulleman





PostPosted: 2004-6-30 19:24:00 Top

java-programmer >> Cannot load image in applet after placing it in a package Just figured it out... it is the localhost.. ( ox )

Applets are allowed to contact the server they are loaded from. The server
is set on IP, the applet is not allowed to contact the localhost. ( >< )

Used the links http://127.0.0.1/Htmledit.htm and
http://192.168.255.136/Htmledit.htm (local network IP), and the images are
loaded.

Just posting a possible solutions for other developers (searching newsgroups
via a searchengine).


"Gerrit Hulleman" <email***@***.com> wrote in message
news:40e29d0a$0$35145$email***@***.com...
> Had tried an app. That works The strange thing is that the problem only
> occures when trying to load the applet using a webserver.
>
> A java application is able to get the image using the '/' prefix. The sun
> applet viewer is able to load the images using the same prefix. Using a
> browser to the htm file
>
(file://localhost/D:/System/eclipse/workspace/htmledit2_test/Htmledit.htm),
> images are loaded. (IE & Opera).
>
> But when the browser loads the applet via the IIS server
> (http://localhost/Htmledit.htm) (set to the same dir as the direct link),
> images are left out.
>
> This only happens if the Htmledit class is in a package. Otherwise images
> are loaded. That is why I think about applet security. But I cannot get my
> finger on it. Any suggestions?
>
>
> "Andrew Thompson" <email***@***.com> wrote in message
> news:17cfr5lkjz6m4$.3naf2umsfgl9$email***@***.com...
> > On Wed, 30 Jun 2004 11:31:51 +0200, Gerrit Hulleman wrote:
> >
> > > This has been a much discussed topic in several newsgroups, but I
still
> > > cannot figure it out.
> >
> > Can you figure it out in an aplication?
> >
> > Do that first.
> >
> > --
> > Andrew Thompson
> > http://www.PhySci.org/ Open-source software suite
> > http://www.PhySci.org/codes/ Web & IT Help
> > http://www.1point1C.org/ Science & Technology
>
>


 
 
Roedy Green





PostPosted: 2004-6-30 19:54:00 Top

java-programmer >> Cannot load image in applet after placing it in a package On Wed, 30 Jun 2004 13:03:45 +0200, "Gerrit Hulleman"
<email***@***.com> wrote or quoted :

>(file://localhost/D:/System/eclipse/workspace/htmledit2_test/Htmledit.htm),
>images are loaded. (IE & Opera).

Read the giant list of things unsigned Applets are not permitted to do
at http://mindprod.com/jgloss/applet.html

Chief among them is read or write the hard disk.

Instead you can read members of the jar file with getResource or
getResourceAsStream. see http://mindprod.com/jgloss/image.html
for sample code.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
 
Andrew Thompson





PostPosted: 2004-6-30 21:16:00 Top

java-programmer >> Cannot load image in applet after placing it in a package On Wed, 30 Jun 2004 11:53:53 GMT, Roedy Green wrote:

> http://mindprod.com/jgloss/applet.html

Good page. Lists some restrictions that
had not occured to me. Could I get you to
expand one entry slightly?

"Applet Restrictions" - point..

FROM
"look at the restricted system properties. "

TO
"look at the restricted system properties or
get an enumeration of the properties. "

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
 
Roedy Green





PostPosted: 2004-7-1 3:57:00 Top

java-programmer >> Cannot load image in applet after placing it in a package On Wed, 30 Jun 2004 13:15:38 GMT, Andrew Thompson
<email***@***.com> wrote or quoted :

>"Applet Restrictions" - point..
>
>FROM
>"look at the restricted system properties. "
>
>TO
>"look at the restricted system properties or
>get an enumeration of the properties. "

done.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.