DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2005

    how to pass image from servlet to applet?

    I am writing a servlet/applet program that displays a http image. e.g.

    since the image is not on the server that host the servlet, seems like the sandbox policy restricted me from displaying the image directly on my applet using getImage() function . So, I would like to ask for your help in preparing the servlet and applet codes for the servlet to pass the image to applet, and then the image is displayed on applet.

    I am a new comer in Java programming, can you please give me the instruction as detail as possible? Thank you very much.

  2. #2
    Join Date
    Nov 2004
    I've done that, some years ago. What I used was a servlet that received the url
    of the image, got the image as a byte stream over the net, converted it into a gif using a gifencoder and send it back to the client.
    Using the servlet was easy, it was included in the html as the target of the src
    parameter on image tags.

    So it did not send the image to the applet as you want, but I guess that could be
    fixed as the applet could get the byte stream and to the image create itself...

    I could dig up the code for you if you like.
    eschew obfuscation

  3. #3
    Join Date
    Jun 2005
    Hi sjalle,

    Thank you very much for your help. I actually understand the logic of what to do with it, but I really don't know how to do it. It would be much helpful if you can give me the code. I desperately need your help. Thank you veyr much.

  4. #4
    Join Date
    Nov 2004

    I found it, I think...

    Here is an applet and a servlet, the applet gets image url as user input
    and calls the servlet with the image url as the only parameter. The
    applet then creates an image from the byte stream returned from the


    I have not tested this, as my server setup is not quite ok at the moment.


    Uuuups ! I have tested the applet and found that i had forgotten something
    public void init() {
          getURLBtn.addActionListener(this); // << essential stuff
    Ive tested it without the servlet, just writing the image url in the url entry
    field, and that works. The servlet is basically doing the same thing as the
    applet, except that it accesses other servers and returns the image byte
    stream to the applet.

    PS: the GifEncoder I mentioned is not required for plain image transfer.
    Attached Files Attached Files
    Last edited by sjalle; 06-08-2005 at 09:06 AM. Reason: deaf button
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.