Loading Images in Applets

Is it possible to use the Toolkit class to load images in "unsigned" applets. I tried that but it throws a security exception:
com.ms.security.SecurityExceptionEx[MyApplet.init]: cannot access file http://localhost/MyApplet/images/Image1.gif
Though I am reading the image from the server not the client machine.
Any help would be appreciated.
Thanks in advance,
Samer Meqdad

Here's the code:
Image img;
img = Toolkit.getDefaultToolkit ().getImage (getCodeBase() +  "images/MyImage.gif");The exception thrown is:
com.ms.security.SecurityExceptionEx[Host]: java.io.IOException: bad path: C:\Documents and Settings\samerm\Desktop\file:\C:\MyApplet\images\MyImage.gif
     at com/ms/security/permissions/FileIOPermission.check (FileIOPermission.java)
     at com/ms/security/PolicyEngine.deepCheck (PolicyEngine.java)
     at com/ms/security/PolicyEngine.checkPermission (PolicyEngine.java)
     at com/ms/security/StandardSecurityManager.chk (StandardSecurityManager.java)
     at com/ms/security/StandardSecurityManager.checkRead (StandardSecurityManager.java)
     at com/ms/awt/WToolkit.getImageFromHash (WToolkit.java)
     at com/ms/awt/WToolkit.getImage (WToolkit.java)
     at DiamondsApplet.init (DiamondsApplet.java:54)
     at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
     at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
     at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
     at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
     at com/ms/applet/AppletPanel.run (AppletPanel.java)
     at java/lang/Thread.run (Thread.java)

Similar Messages

  • Loading Images into Applets

    I've been having problems loading an image into an Applet. I've found that when the getImage() call is put into the init() method it loads the image fine, also implementing an imageUpdate call. However, now I'm trying to expand on this by putting it into a button click, it hangs indefinitely while waiting for the image to load.
    Another interesting point I've noticed is that the Canvas subclass ImageSegmentSelector uses a PixelGrabber in its constructor to put the Image into a buffer - when this class is created from the imageUpdate() call, NOT the init() call, the grabPixels() call hangs indefinitely too!!
    Any feedback, please,
    Jonathan Pendrous
    import java.applet.*;
    import java.net.*;
    import jmpendrous.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    public class XplaneGlobalSceneryDownloader extends Applet implements ActionListener{
    ImageSegmentSelector worldMap;
    Image img;
    URL url;
    int longtitude = 36;
    int latitude = 18;
    boolean imageLoaded;
    TextField t1, t2,t3;
    Label l1,l2,l3;
    Button b1;
    Applet a1;
    public void init() {
    a1 = this;
    l1 = (Label) add(new Label("Number of horizontal sections: "));
    t1 = (TextField) add(new TextField("45",3));
    l2 = (Label) add(new Label("Number of vertical sections: "));
    t2 = (TextField) add(new TextField("45",3));
    l3 = (Label) add(new Label("URL of image file: "));
    t3 = (TextField) add(new TextField("file:///C:/java/work/xplane_project/source/world-landuse.GIF",60));
    b1 = (Button) add(new Button("Load image"));
    b1.addActionListener(this);
    validate();
    // THIS CODE WORKS FINE ...
    /*try { url = new URL("file:///C:/java/work/xplane_project/source/world-landuse.GIF"); }
    catch(MalformedURLException e) { System.exit(0);   }
    img = getImage(url);
    //int w=img.getWidth(this);
    while(imageLoaded==false) { try { Thread.sleep(1000);   } catch(InterruptedException e) {System.exit(0);    } }
    worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
    add(worldMap);
    //resize(worldMap.getWidth(), worldMap.getHeight());
    validate();*/
    //repaint();
    //worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
    //repaint();
    public void actionPerformed(ActionEvent e) {
    try { longtitude = Integer.parseInt(t1.getText()); } catch (NumberFormatException ex) {System.exit(0); }
    try { latitude = Integer.parseInt(t2.getText()); } catch (NumberFormatException e2) {System.exit(0); }
    try { url = new URL(t3.getText()); }
    catch(MalformedURLException e3) { System.exit(0);   }
    img = getImage(url);
    //int w=img.getWidth(this);
    while(imageLoaded==false)
    { try { Thread.sleep(1000);   } //KEEPS ON LOOPING
    catch(InterruptedException e4) {System.exit(0);    } }
    worldMap = new ImageSegmentSelector(a1, img, longtitude, latitude);
    add(worldMap);
    //resize(worldMap.getWidth(), worldMap.getHeight());
    validate();
    public boolean imageUpdate(Image i, int flags, int x, int y, int w, int h){
    // THIS NEVER GETS CALLED AT ALL //
    if (((flags & ImageObserver.WIDTH) != 0) && ((flags & ImageObserver.HEIGHT) != 0)) {
    //worldMap = new ImageSegmentSelector(this, i, longtitude, latitude);
    //add(worldMap);
    //validate();
    //repaint();
    imageLoaded = true;
    return false;
    return true;
    }

    Sorry, thought this had been lost.
    You can load a file if the applet itself is run from the local filesystem - it loads it fine from the init(), but not otherwise. But I haven't got the applet to run from a browser yet without crashing (it's OK in the IDE debugger), so that's the next step.

  • Best place to load Images in applet game

    Sorry for the double post but I just realised I originally posted this in completely the wrong forum!
    Hello,
    I have made a fairly basic game of 21/BlackJack and was wondering where the best place to load the card Images is/was...
    Currently I am loading the images into an Image[ ] in the applet class, but was thinking maybe the loading should be done in the deck or card class?
    In the applet class I use an ordered version of the deck to assign the cards in the image[ ], then to call an image I generate an index number based on the current cards value and suit....
    However this method means I have to create an instance of the deck in the main program, whereas before I had it as a private member of the dealer class, so only the dealer could access it (which seems "safer", no?)
    So would a better idea be to have a loadImage() method in the deck class, which populates an Image[ ] with the cards and pass this to the main program?
    Thanks

    Ken,
    Loading images is slow so you only want to do it once... maybe when you generate the deck ... and "image" is definately an attribute of the card, yes... I'd actually implement the loadImage() as a method in the card class so set a private image variable... and then get the the dealer to call the loadImage method for each card as "he" builds the deck.
    But that's just how I would do it... and I'm no guru so don't take it as gospel... I'd be surprised if there wasn't atleast one "purer" way of doing it.

  • Loading images inside applet JAR

    Hi
    This is my issue: I have an applet which contains images inside the applet JAR. I want to display these images in my applet, but apparently due to browser access restrictions, I'm not allowed.
    My first code was like this:
    //security restrictions on browsers do not allow getResource
    ImageIO.read(MyClass.class.getResource("imgs/img.png"));
    //getResourceAsStream should be allowed by browsers
    ImageIO.read(MyClass.class.getResourceAsStream("imgs/img.png"));Both lines work when I execute the applet locally (command line / programming IDE), but when I deploy it to my web server, the resource "imgs/img.png" becomes a relative URL to my web application context (like /webcontext/MyClass/imgs/img.png). It works locally because the call to getResource returns a URL object with "file:" protocol, but I need it to look for my images bundled inside the JAR, not web hosted images.
    I need to avoid making the applet look for these images as a web resource... how can I do it?
    Thanks!

    dev@java wrote:
    warnerja wrote:
    I'm not convinced the code you posted wouldn't work, but since this is an applet, you have access to the Applet class. Check out the Applet.getImage method in conjunction with Applet.getCodeBase.
    [http://java.sun.com/javase/6/docs/api/java/applet/Applet.html]
    getCodeBase returns my web context, like http://myhost.com/mycontext/ , so it is pretty much the same as above.
    Thanks for your replyThat is the way to load resources though. Hence back to my earlier statement about not being convinced it would not work, with this addition: It should work, assuming you actually do have the resources properly located with the web app, whether they be in a jar, or loose files relative to where the web app is. My guess at this point is that they are not.

  • Problem with loading image to Applet.

    Hello. Im preety new to Java, and currently ive got problems with adding an image to my applet. I tried to make game, similar to Mario - a platform based one. I found a source code of something close to that, and wanted to test but i couldnt get images loading. Here's the code :
    Main class :
    package pl.wat.edu;
    import java.applet.*;
    import java.awt.*;
    public class Main extends Applet implements Runnable{
         Thread th;
         private final int speed = 15;
         private Level obecny_poziom;
         private Image dbImage;
         private Graphics dbg;
         MediaTracker mt = new MediaTracker(this);
         private Image ziemia1;
         @Override
         public void destroy() {
              // TODO Auto-generated method stub
              super.destroy();
         @Override
         public void init() {
              // TODO Auto-generated method stub
              super.init();
              setSize(stale.wielkosc_apletu_szerokosc, stale.wielkosc_apletu_wysokosc);
              //setBackground(Color.blue);
              //ziemia1 = getImage(getCodeBase(), "g1.GIF");
              obecny_poziom = new Pierwszy(this, this);
         @Override
         public void start() {
              // TODO Auto-generated method stub
              super.start();
              // create new thread
              th = new Thread (this);
              // start thread
              th.start ();
         @Override
         public void stop() {
              // TODO Auto-generated method stub
              super.stop();
              // Thread stop
              th.stop();
              th = null;
         public void run() {
              // TODO Auto-generated method stub
              while (true){
                   repaint();
                   try
                        Thread.sleep(speed);
                   catch (InterruptedException ex)
                   // do nothing
         @Override
         public void paint(Graphics arg0) {
              // TODO Auto-generated method stub
              super.paint(arg0);
              //arg0.drawImage(ziemia1,10,10,this);
              obecny_poziom.paintLevel(arg0);
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint(dbg);
              g.drawImage (dbImage, 0, 0, this);
    }and Level class that have draw levels from String rows :
    package pl.wat.edu;
    import java.applet.Applet;
    import java.awt.*;
    public abstract class Level {
         //private LevelElement [] elements;
         private WorldTile [] tiles;
         private WorldTile[][] tablica_kolizji;
         private Color [] colors;
         private Component parent;
         private int lewa_granica;
         private int prawa_granica;
         private int dlugosclevelu;
         private Image ziemia = null;
         private Image titi;
         private Applet applet;
         public abstract void resetLevel();
         public Level(Component parent, Applet applet) {
              super();
              this.parent = parent;
              this.applet = applet;
              ziemia = applet.getImage(applet.getCodeBase(), "g1.GIF");
         public void initializeLevel(String [] definitions){
              tablica_kolizji = new WorldTile [stale.dlugosclevela] [definitions[0].length()];
              lewa_granica = 0;
              prawa_granica = stale.wielkosc_apletu_szerokosc;
              int licznik_kratek = 0;
              for(int i=0; i<definitions.length; i++){
                   char [] definition_line = definitions.toCharArray();
                   for(int j=0; j<definition_line.length; j++){
                        if (definition_line[j] == ':')
                             tablica_kolizji[i][j] = null;
                        else if (definition_line[j]== 'g'){
                             Ziemia tile = new Ziemia(j*stale.szerokoscTile, i*stale.wysokoscTile, stale.ziemia_id, ziemia, parent);
                             tablica_kolizji[i][j] = tile;
                             licznik_kratek = 0;
              tiles = new WorldTile [licznik_kratek];
              int licznik = 0;
              for (int i = 0; i<tablica_kolizji.length; i++){
                   for(int j=0; j>tablica_kolizji[i].length; j++){
                        if (tablica_kolizji[i][j] != null){
                             tiles[licznik] = tablica_kolizji[i][j];
                             licznik++;
         public void paintLevel(Graphics g)
              try
                   // draw background
                   // draw all elements in elements array
                   for(int i=0; i<tiles.length; i++)
                        tiles[i].rysujTile(g);
              catch(Exception ex)
                   // do nothing
    Any ideas why this Image doesnt show up ?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    michali7x4s1 wrote:
    Thats a code i found somewhere, tried to check how some things work.Have you used exceptions before? If not, please read the sun tutorial on them as they are very very important. Also, whether this is your code or someone else's doesn't matter as it's yours now, and you would be best served by never throwing out exceptions as is done in this code. It's like driving with a blindfold on and then wondering why you struck the tree. It's always best to go through the tutorials to understand code before using it. If it were my project, I'd do it in Swing, not AWT. Fortunately Sun has a great tutorial on how to code in Swing, and I suggest you head there as well. Best of luck.

  • Loading Images in Applications

    Hi.
    I know how to load images in applets with the getImage method that comes with the Applet class, but I cant seem to find a way to do it in an application.
    I found a Toolkit class, but that required me to extend it when I am already extending the Frame class.
    The Frame class comes with a getImage method, but that requires a getCodeBase() method that comes with the applet class.
    How would I get an image using an application?
    Thanks in advanced
    Glen.

    You don't need to extends Toolkit to impelement its abstract method. you can get default Toolkit by calling static method in Toolkit, getDefaultToolkit().
    Toolkit kit = Toolkit.getDefaultToolkit();

  • Problem loading images in my applet

    Hi guys,
    When i test my Applet using an IDE the images are loaded fine, however when I run my applet using a browser it wont load the images.
    I think it is because I use this line:
    System.getProperty("java.class.path",".")My question is, how do you load images into an applet without signing it.
    Any help would be great.
    Alex

    Axilliary files like images, properties files etc. which are essentially part of the program are refered to as "resources". The best way to access these files is by the getResource() methods in the Class or ClassLoader objects. If you do it that way then the JVM reads them exactly the same way it reads .class and from the same place.
    Say your using an image, say my.gif from a class called MyClass. You put the image file in the same directory as the MyClass.class file. Then, in MyClass, you do:
    static ImageIcon myImage = new ImageIcon(MyClass.class.getResource("my.gif"), "MY Image");That will pick up the image from a file, from an http connection, from a jar, of from any combination of same.

  • Display images in applets

    hi every body.
    I want to display images in an applet when i invoke it from the jsp page . it is not working. the code is as follows.
    <html>
    <body>
    <jsp:plugin type = "applet"
         code ="Welcome.class"
         width="475" height = "350" >
    </jsp:plugin>
    </body>
    </html>
    while the code of "Welcome.java" is as follows.
    ImageIcon image = new ImageIcon("aa.gif");
    JButton button = new JButton(image);
    i have placed the aa.gif file in the same directory where i placed the Welcome.class and the jsp file.
    when i run this program the i recieve the message that the applet is not loaded.
    can some body help me how to place images in applets.
    thanks.

    You should be able to test that applet on you hard drive first. If it works check the case of the image file.
    Web servers look for case. If you are asking for ImageIcon img = new ImageIcon("abc.gif") and what is loaded on your web server is "abc.GIF" it won't find it. Same goes for basic HTML tags like
    <Img src=abc.gif>. But it will find it on you hard drive when you run the applet there.

  • Help with images within applets

    I created a card game applet which calls images placed within the same directory. In appletviewer the game runs fine,not in browsers. I downloaded the browser plugin since i use swing classes. If I remove the image the applet loads up without the grafix. Here is the IO error generated. I thought applets can read files within the same directory and sub directories? Would creating a jar file solve this problem? Anyhelp would be appreciated.
    java.security.AccessControlException: access denied (java.io.FilePermission main2.gif read)

    When running in a browser, your applet must be signed in order to be able to access local resources. Check out the "Signed Applets" forum for many discussions about this, as well as methods for signing applets.

  • Saving image in applet

    i used the following code to save a image it displays from applet.it works fine in appletviewer
    BufferedImage expImage = new BufferedImage( (int)this.getWidth(), (int)this.getHeight(), BufferedImage.TYPE_INT_RGB );
    Graphics g2d = expImage.getGraphics();
    // draftGrid.update(g2d);
    this.update(g2d);
    g2d.dispose();
    OutputStream out = new FileOutputStream( "guru.jpg");
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(expImage);
    out.flush();
    out.close();
    expImage.flush();
    but when i run it in html through my web server the image does' get saved and it the exception i go is
    Status code:404 request:R( j
    ava/awt/image/BufferedImage.class + null) msg:null
    what should i go to save a image from applet throgh browser

    Hello,
    This is what I am doing through a servlet call.
    If you are just going to let the user download the image you could try the following:
    // This works if we are just going to download the image as is
    URL url = new URL(request.getParameter("imageURL"));
    response.setContentType("image/gif");
    response.setHeader("Content-Disposition", "attachment; "+
         "filename=\"image.gif\"");
    byte buf[] = new byte[1024];
    InputStream inputStream = url.openStream();
    ServletOutputStream out = response.getOutputStream();
    //Read and Write
    while(inputStream.read(buf) != -1)
    out.write(buf);
    out.flush();
    out.close();
    Or if you are going to manipulate the image a bit before they download it you could try the following:
    URL url = new URL(request.getParameter("imageURL"));
    response.setContentType("image/gif");
    response.setHeader("Content-Disposition", "attachment; "+
         "filename=\"image.gif\"");
    // use ImageIcon because we are getting the image from a
    // URL which might be slow - it has the MediaTracker built right in
    javax.swing.ImageIcon ii = new javax.swing.ImageIcon(url);
    Image image = ii.getImage(); // now the pixel data is in memory
    // get the height and width of the loaded image
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    // create a rectangle as big as the image
    Rectangle drawRect = new Rectangle(10, 10, width, height);
    BufferedImage bufImage = new BufferedImage(width,
    height, BufferedImage.TYPE_INT_RGB);
    // get the graphics so you can draw on it
    Graphics2D g = bufImage.createGraphics();
    // create a nicce white background for the image
    g.setColor(Color.white);
    g.fillRect(0, 0, width, height);
    // reset the color
    g.setColor(Color.black);
    // add the image
    g.drawImage(image, 0, 0, null);
    // add any other things you want as well
    g.drawString("Just a string", 10, 10);
    // create the output stream
    ServletOutputStream out = response.getOutputStream();
    JPEGImageEncoder jpegImageEncoder = JPEGCodec.createJPEGEncode(out);
    // encode it
    jpegImageEncoder.encode(bufImage);
    out.flush();
    out.close();
    Hope that this helps.
    Mike

  • Loading images into memory

    I have an applet that I need to load images into memory. For instance, lets say I am in the first section of the applet. While that section is being showed, I want to load the background image of the second section into memory.
    To load the initial image into momory, I am just using a Mediatracker. No problem there. But I don't want to load all 20 backgrounds into memory at the same time as they take a lot of time. My understanding is that if I create a new MediaTracker while the first chapter is running, it will potentially cause some chaos, as that will stop my thread from running while I have an image loading.
    Somebody told me perhaps I could create a new thread and have that thread load the backgroudn into momory? Perhaps something like this?
    public class TestClass extends JApplet {
         private TestClass thisClass;
         public void init() {
              thisClass = this;
              Runnable r = new Runnable() {
                   public void run() {
                        MediaTracker tracker = new MediaTracker(thisClass);
                        Image nextImage = getImage( getDocumentBase(), getImagePath() +"img1.jpg");
                        tracker.addImage(nextImage,0);
                        try {
                             tracker.waitForID(0);
                        } catch (InterruptedException ie) {
                             System.out.println(ie.toString());
              Thread t = new Thread(r);
              t.setDaemon(false);
              t.start();
              while(t.isAlive()) {
                   int i = 1;     
              t.stop();
              t.destroy();
    }No idea if I am on the right track or not? Another friend told me something about swing helpers but couldn't tell me much more?
    Thanks in advance!

    I use media tracker when I need information about how percent the image is loaded. you can use JLabel to load the images since it has own image observer in it.
    hope you just want to deal with it. easiest way I can offer :)

  • Problem in sending image from applet to servlet

    dear friends,
    i have a need to send an image from applet to servlet via HttpConnection and getting back that image from applet.
    i am struggling with this sice many hours and got tired by searching any post that would help me but haven't got yet.
    i tried using this code but it dosent make any execution sit right. i got NPE at ImageIcon.getDescription() line;
    at applet side
          jf.setContentPane(getJContentPane());
                     FileDialog fd=new FileDialog(jf,"hi");
                     fd.setMode(FileDialog.LOAD);
                     fd.setVisible(true);   
                     v=new Vector();
                     try{                                                
                               FileInputStream fis=new FileInputStream(new File(fd.getDirectory()+fd.getFile()));      
                               byte[] imgbuffer=new byte[fis.available()];
                               fis.read(imgbuffer);
                               ImageIcon imgdata=new ImageIcon(imgbuffer);
                               v.add(0,imgicon);
                                String strwp ="/UASProject/Storeimage";              
                                URL servletURL = new URL(getCodeBase(),strwp);             
                                HttpURLConnection servletCon = (HttpURLConnection)servletURL.openConnection();       
                                servletCon.setDoInput(true); 
                                servletCon.setDoOutput(true);
                                servletCon.setUseCaches(false);
                                servletCon.setDefaultUseCaches(false);   
                                servletCon.setRequestMethod("POST");     
                                servletCon.setRequestProperty("Content-Type", "application/octet-stream");   
                                servletCon.connect();            
                                ObjectOutputStream oboutStream = new ObjectOutputStream(servletCon.getOutputStream());                     
                                oboutStream.writeObject(v);
                                v.remove(0);
                                oboutStream.flush();      
                                oboutStream.close();  
                                //read back from servlet
                                ObjectInputStream inputStream = new ObjectInputStream(servletCon.getInputStream());
                                 v= (Vector)inputStream.readObject();                     
                                 imgicon=(ImageIcon)v.get(1);
                                 showimg.setIcon(imgicon);
                                 this.getContentPane().validate();
                                 this.validate();  
                                inputStream.close();                                                        
                             //  repaint();
                     }catch(Exception e){e.printStackTrace();}  and this is at servlet side
            try {       
                         Vector v=new Vector();                    
                         ObjectInputStream inputFromjsp = new ObjectInputStream(request.getInputStream());                                      
                          v = (Vector)inputFromjsp.readObject();                                                                                                          
                          imgicon=(ImageIcon)v.get(0);                     
                          inputFromjsp.close();            
                          System.out.println(imgicon.getDescription());                                      
                          v.remove(0);
                          v.add(1,imgicon);
    //sending back to applet
                           response.setContentType("application/octet-stream");
                          ObjectOutputStream oboutstream=new ObjectOutputStream(response.getOutputStream());            
                          oboutstream.writeObject(v);
                          oboutstream.flush();
                          oboutstream.close();
                   } catch (Exception e) {e.printStackTrace();}  i really need your help. please let me out of this headche
    thanks
    Edited by: san_4u on Nov 24, 2007 1:00 PM

    BalusC wrote:
    san_4u wrote:
    how can i made a HttpClient PostMethod using java applets? as i have experience making request using HttpURLConnection.POST method. ok first of all i am going make a search of this only after i will tell. please be onlineOnce again, see link [3] in my first reply of your former topic.
    yeah! i got the related topic at http://www.theserverside.com/tt/articles/article.tss?l=HttpClient_FileUpload. please look it, i am reading it right now and expecting to be reliable for me.
    well what i got, when request made by html code(stated above) then all the form fields and file data mixed as binary data and available in HttpServletRequest.getinputstream. and at servlet side we have to use a mutipart parser of DiskFileItemFactory class that automatically parse the file data and return a FileItem object cotaing the actual file data,right?.You can also setup the MultipartFilter in your environment and don't >care about it further. Uploaded files will be available as request attributes in the servlet.is the multipartfilter class file available in jar files(that u suggested to add in yours article) so that i can use it directly? one more thing the import org.apache.commons.httpclient package is not available in these jar files, so where can got it from?
    one mere question..
    i looked somewhere that when we request for a file from webserver using web browser then there is a server that process our request and after retrieving that file from database it sends back as response.
    now i confused that, wheather these webservers are like apache tomcat, IBM's webspher etc those processes these request or there is a unique server that always turned on and process all the request?
    because, suppose in an orgnisation made it's website using its own server then, in fact, all the time it will not turned on its server or yes it will? and a user can make a search for kind of information about this orgnisation at any time.
    hopes, you will have understand my quary, then please let me know the actual process
    thanks
    Edited by: san_4u on Nov 25, 2007 11:25 AM

  • Issues with Loading Images from a Jar File

    This code snippet basically loops through a jar of gifs and loads them into a hashmap to be used later. The images all load into the HashMap just fine, I tested and made sure their widths and heights were changing as well as the buffer size from gif to gif. The problem comes in when some of the images are loaded to be painted they are incomplete it looks as though part of the image came through but not all of it, while other images look just fine. The old way in which we loaded the graphics didn't involve getting them from a jar file. My question is, is this a common problem with loading images from a jar from an applet? For a while I had tried to approach the problem by getting the URL of the image in a jar and passing that into the toolkit and creating the image that way, I was unsuccessful in getting that to work.
    //app is the Japplet
    MediaTracker tracker = new MediaTracker(app);
    //jf represents the jar file obj, enum for looping through jar entries
    Enumeration e = jf.entries();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    //buffer for reading image stream
    byte buffer [];
    while(e.hasMoreElements())
    fileName = e.nextElement().toString();
    InputStream inputstream = jf.getInputStream(jf.getEntry(fileName));
    buffer = new byte[inputstream.available()];
    inputstream.read(buffer);
    currentIm = toolkit.createImage(buffer);
    tracker.addImage(currentIm, 0);
    tracker.waitForAll();
    images.put(fileName.substring(0, fileName.indexOf(".")), currentIm);
    } //while
    }//try
    catch(Exception e)
    e.printStackTrace();
    }

    compressed files are not the problem. It is just the problem of the read not returning all the bytes. Here is a working implementation:
    InputStream is = jar.getInputStream(entry);
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    try{
    byte[] buf = new byte[1024];
    int read;
    while((read = is.read(buf)) > 0) {
    os.write(buf, 0, read);
    catch(Exception e){
         e.printStackTrace();
         return null;
    image = Toolkit.getDefaultToolkit().createImage(os.toByteArray());
    This works but I think you end up opening the jar a second time and downloading it from the server again. Another way of getting the images is using the class loader:
    InputStream is = MyApplet.class.getResourceAsStream(strImageName);
    In this case, the image file needs to be at the same level than MyApplet.class but you don't get the benefit of enumerating of the images available in the jar.

  • Loading images from jar file

    i use the instruction below to load image contained in my jar file for distribution application but the image doesn't appear
    icon = new ImageIcon("images/logo_tunisiana.GIF");
    the jar file contain the image under a subdirectory called images.
    Witch code sample have i to use ?
    thanks in advance

    I have an applet that is packaged in a jar file with images. I can access the images using:
    aIcon = new ImageIcon(KeyboardApplet.class.getResource("images/keyimages/a.jpg"));

  • Loading Images in JavaFX

    Can someone please explain how to load images in JavaFX? Or point me to a tutorial?
    All the answers I've seen use the __DIR__/imagename.ext to get the image. However, I have a decent sized project and do not want all my images in the same package.
    src/package/FXClass
    src/resources/images/imagename.ext
    Please, what do I do to load 'imagename.ext' in the JavaFX class 'FXClass'?
    Thanks.

    __DIR__ is a URL. It could be an http:, jar: or a file: URL. If it's a jar: URL, then it's going to be something like:
    jar:file:/my/project/path/dist/myproject.jar!/java/mainYou can use the java String API or java URL API to make a new URL of jar:file:/my/project/path/dist/myproject.jar!/java and set your ROOT variable to that.
    This code from the media browser tutorial (from Constants.fx) does something similar. Notice the javafx.application.codebase property. When you run the tutorial from javafx.com, the codebase is http://javafx.com/docs/tutorials/mediabrowser/dist/ and all of the sample thumbnails and images are in thumbs and images directory (respectively).
    * When running as an application or launcing in the browser from NetBeans,
    * the sample images and thumbnails can be loaded from the jar file. But when
    * deploying as an applet, putting all of these images in the jar file
    * would bloat the jar file unnecessarily. In the applet case the images
    * should be loaded from a server.
    * <p>
    * When running in the browser, the javafx.application.codebase property will
    * be set to the applet's codebase URL. For the Media Browser tutorial, the
    * sample images and thumbs are stored in directories rooted at this URL.
    * The javafx.application.codebase property can be used, therefore, to locate
    * the sample images and thumbnails.
    package def CODEBASE : String = {
        var codebase = FX.getProperty("javafx.application.codebase");
        // If we don't have a codebase defined, or codebase starts with "file:",
        // assume we're running locally and load images from the jar.
        if ( codebase == "" or codebase.startsWith("file:") ) {
            codebase = __DIR__
        codebase
    }

Maybe you are looking for

  • Game Center keeps crashing our games. How do we uninstall and reinstall "Game Center" on iPad2

    Hi there, we use an iPad2 running iOS version 4.3.3 (8J2 - whatever that means), and we keep running into a persistent problem which is that games keep crashing after a few minutes. I am fairly certain this is somehow connected to how they interact w

  • Issues Transferring Video Purchased on iTunes to My Video iPod..Help!

    Just bought a new 60 BG Video iPod. I purchased a few videos from iTunes. However, when I connect my iPod to iTunes, only my music is transferred. The videos are not transferred. When I try to transfer the video to my iPod, I get the following messag

  • Iphone 2.0 App

    Have anyone experienced difficulties pairing Apple bluetooth with the iphone after uploading 2.0 app.? i have not been able to syn at all...thought maybe there is a problem w/ my bluetooth.

  • Running J2ME code in a J2SE VM

    Is it possible to use J2ME classes in J2SE? Could I include some jar with, for example, javax.microedition.lcdui.Image, and use that class in a J2SE program? If so, which jar? thanks, Abraham

  • How to recover photo stream pictures?

    My photo stream album disappeared.  I think it happened when I enabled the "iCloud Photo Library (beta)".  I thought it was suppose to upload the photo stream album to iCloud but instead it just deleted it without ever asking me if I wanted them to b