3 Replies Latest reply on Dec 9, 2011 11:01 AM by rhusar

    save image in webapp/resources

    myrabbitrules

      Hi,

       

      we want to save in image in our war as "webapp/resources/file.gif". But default file root is "C:\jboss-as-7.0.2.Final\bin\" where we don't want our file to be saved.

      How can be save in webapp folder?

       

      BufferedImage img = new BufferedImage(p.getWidth(),p.getHeight(), BufferedImage.TYPE_INT_RGB);
      p.paint(img.createGraphics());
      ImageIO.write(img, "GIF", new File(Dateiname + ".gif"));
        • 1. Re: save image in webapp/resources
          rhusar

          Rather then answering the question you shoudl revise why you want to do that. This looks like a bad idea to me. If the images are permanent (which is unlikely since you want to store it with the app) then store it elsewhere in the filesystem or database. If the images are temporary store them in the memory (eg cache).

          • 2. Re: save image in webapp/resources
            myrabbitrules

            I tried storing the image in local filesystem. But i then couldn't access image in xhtml. I guess this is because all content must be placed in deployed war (which does not contain stuff from local filesystem).

             

            Concerning storing them in memory: How do I do that? Do you mean storing image as byte[]? If so I'm struggling with finding tags that accept byte[]. I found one in seam tag library, but I don't know if I can install seam tag library with jboss7 and maven.

            • 3. Re: save image in webapp/resources
              rhusar

              Well, its a fact that serving static images via Java is slower than letting Apache HTTPd serve them.

               

              Thats why I think a better approach is to store images on the filesystem where HTTPd just serves them statically. In your Java side all you need is to send in your respose <img src="/static/images.png" /> and the context static just let the apache to handle and not pass all the way to Java. You will also have to handle deletion from the FS, authorization might become little bit more complicated. Anyway, depends on your use case :-)

               

              HTH,

              Rado