Cannot load image in applet after placing it in a package

Discussion in 'Java' started by Gerrit Hulleman, Jun 30, 2004.

  1. 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
    Gerrit Hulleman, Jun 30, 2004
    #1
    1. Advertising

  2. 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, Jun 30, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:17cfr5lkjz6m4$.3naf2umsfgl9$...
    > 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, Jun 30, 2004
    #3
  4. 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" <> wrote in message
    > news:17cfr5lkjz6m4$.3naf2umsfgl9$...
    >> 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
    Andrew Thompson, Jun 30, 2004
    #4
  5. 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" <> wrote in message
    news:40e29d0a$0$35145$4all.nl...
    > 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" <> wrote in message
    > news:17cfr5lkjz6m4$.3naf2umsfgl9$...
    > > 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, Jun 30, 2004
    #5
  6. Gerrit Hulleman

    Roedy Green Guest

    On Wed, 30 Jun 2004 13:03:45 +0200, "Gerrit Hulleman"
    <> 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.
    Roedy Green, Jun 30, 2004
    #6
  7. 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
    Andrew Thompson, Jun 30, 2004
    #7
  8. Gerrit Hulleman

    Roedy Green Guest

    On Wed, 30 Jun 2004 13:15:38 GMT, Andrew Thompson
    <> 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.
    Roedy Green, Jun 30, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    401
    jagdish Lakshminarayanan
    Nov 16, 2005
  2. Krista
    Replies:
    3
    Views:
    2,301
    Andrew Thompson
    Sep 15, 2004
  3. Mark_Galeck
    Replies:
    1
    Views:
    290
    Roedy Green
    Oct 27, 2008
  4. xbound

    Placing controls after a gridview

    xbound, May 21, 2010, in forum: ASP .Net
    Replies:
    5
    Views:
    315
    Alexey Smirnov
    May 21, 2010
  5. SamuelXiao
    Replies:
    2
    Views:
    1,335
    SamuelXiao
    Jan 21, 2011
Loading...

Share This Page